简体   繁体   中英

How to add the Horizontal line between two QLineEdit like following with pyqt?

如何在两个QLineEdit之间添加水平线,请忽略汉字?

There is no function that performs your task, but you can create a widget that has that characteristic:

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_()) 

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM