如何在两个 QLineEdit 之间添加水平线,如下面的 pyqt?
Posted
技术标签:
【中文标题】如何在两个 QLineEdit 之间添加水平线,如下面的 pyqt?【英文标题】:How to add the Horizontal line between two QLineEdit like following with pyqt? 【发布时间】:2017-04-20 13:34:56 【问题描述】:如何在两个QLineEdit之间添加水平线,请忽略中文?
【问题讨论】:
看看这个例子***.com/a/26369850/7742341 【参考方案1】:没有功能可以执行您的任务,但您可以创建一个具有该特性的小部件:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class LineEdits(QWidget):
def __init__(self, pen=QPen(), parent=None):
super(LineEdits, self).__init__(parent=None)
layout = QHBoxLayout(self)
self.lineEdit1 = QLineEdit(self)
layout.addWidget(self.lineEdit1)
spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
layout.addItem(spacerItem)
self.lineEdit2 = QLineEdit(self)
layout.addWidget(self.lineEdit2)
self.pen = pen
def paintEvent(self, event):
QWidget.paintEvent(self, event)
painter = QPainter(self)
painter.setPen(self.pen)
start = self.lineEdit1.pos() + QPoint(self.lineEdit1.width(), self.lineEdit1.height()/2)
stop = self.lineEdit2.pos() + QPoint(0, self.lineEdit2.height()/2)
painter.drawLine(start, stop)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
w = LineEdits(pen=QPen(Qt.black, 2))
w.show()
sys.exit(app.exec_())
【讨论】:
非常感谢您的帮助。以上是关于如何在两个 QLineEdit 之间添加水平线,如下面的 pyqt?的主要内容,如果未能解决你的问题,请参考以下文章
如何使 QPushButtons 将文本添加到 QLineEdit 框中?