Add a click on QLineEdit

后端 未结 3 407
清酒与你
清酒与你 2021-01-15 06:32

I am working on set a click() event to QLineEdit, I already successfully did it. But I want to go back to Mainwindow when the QLine Edit is clicked because I need the data i

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-15 07:12

    I use the following to connect any method as the callback for a click event:

    class ClickableLineEdit(QLineEdit):
        clicked = pyqtSignal() # signal when the text entry is left clicked
    
        def mousePressEvent(self, event):
            if event.button() == Qt.LeftButton: self.clicked.emit()
            else: super().mousePressEvent(event)
    

    To use:

    textbox = ClickableLineEdit('Default text')
    textbox.clicked.connect(someMethod)
    

    Specifically for the op:

    self.tc = ClickableLineEdit(self.field[con.ConfigFields.VALUE])
    self.tc.clicked.connect(self.mouseseleted)
    

提交回复
热议问题