Add a click on QLineEdit

后端 未结 3 440
清酒与你
清酒与你 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:04

    This is what I used to do onClick for QLineEdits

    class MyLineEdit(QtGui.QLineEdit):
    
        def focusInEvent(self, e):
            try:
                self.CallBack(*self.CallBackArgs)
            except AttributeError:
                pass
            super().focusInEvent(e)
    
        def SetCallBack(self, callBack):
            self.CallBack = callBack
            self.IsCallBack = True
            self.CallBackArgs = []
    
        def SetCallBackArgs(self, args):
            self.CallBackArgs = args
    

    and in my MainGUI:

    class MainGUI(..):
    
        def __init__(...):
            ....
            self.input = MyLineEdit()
            self.input.SetCallBack(self.Test)
            self.input.SetCallBackArgs(['value', 'test'])
            ...
    
        def Test(self, value, test):
            print('in Test', value, test)
    

提交回复
热议问题