Reputation: 5
How to add the Horizontal line between two QLineEdit, please ignore the Chinese words?
Upvotes: 0
Views: 2222
Reputation: 243955
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_())
Upvotes: 1