Add a click on QLineEdit

后端 未结 3 408
清酒与你
清酒与你 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 06:57

    Just simply call the MainWindow mousePressEvent and give it the event variable the line edit received

    class MyLineEdit(QtGui.QLineEdit):
    
        def __init__(self, parent):
    
            super(MyLineEdit, self).__init__(parent)
            self.parentWindow = parent
    
        def mousePressEvent(self, event):
            print 'forwarding to the main window'
            self.parentWindow.mousePressEvent(event)
    

    Or you can connect a signal from the line edit

    class MyLineEdit(QtGui.QLineEdit):
    
        mousePressed = QtCore.pyqtProperty(QtGui.QMouseEvent)
    
        def __init__(self, value):
    
            super(MyLineEdit, self).__init__(value)
    
        def mousePressEvent(self, event):
            print 'forwarding to the main window'
            self.mousePressed.emit(event)
    

    Then just connect the signal in your main window where you created it

        self.tc = MyLineEdit(self.field[con.ConfigFields.VALUE])#self.tc = wx.TextCtrl(self.parent, -1, str(field[con.ConfigFields.VALUE]), pos=(x+220, y-3), size=(200, -1))
        self.tc.mousePressed[QtGui.QMouseEvent].connect(self.mousePressEvent)
    

提交回复
热议问题