简体   繁体   中英

Send data processed from one window to mainwindow in pyqt

I am using pyqt to build a gui, using the .UI file from qt Designer, and then convert by pyuic4.

I have two windows,
1st - mainwindow (which has some label and buttons)
2nd - Window is a numeric keypad input window.

I have the .py of the UI file seperate and load it in main program by

class mainwindow(QtGui.QWidget):
    def __init__(self, parent = None):
        super(mainwindow, self).__init__(parent)
        self.ui = Ui_main()
        self.ui.setupUi(self)
# this is same for keypad window also..
# Inside the keypad window class i have added functions for click & display events.

When I click a button in mainwindow, the num keypad window should open. (I have done this successfully)

the main code is as follows,

def main():
    app = QtGui.QApplication(sys.argv)
    home = mainwindow()   #mainwindow object
    keypad = keypad()     #keypad object
    home.ui.set_btn.clicked.connect(keypad.show)  #keypad window will show if press set_btn
    homewindow.show()
    sys.exit(app.exec_())

I enter values using keypad and it is shown in the space provided in the same window.

now I have to return that entered value to the main window to update the value.

This seems to be a simple question, but I couldnt find plz help me.

*is there any existing method for keypad operations, in qtdesigner or pyqt??
Only an idea would also be sufficient..

Thanks !!!

What you want, is to define a new method to handle your return value.

In your mainwaindow you define the handler:

class mainwindow(QtGui.QWidget):
   def __init__(self, parent = None):
      super(mainwindow, self).__init__(parent)
      self.ui = Ui_main()
      self.ui.setupUi(self)
   def keypadHandler(self, value):
       # handle the value here

And then, just like you connect the signal from the mainwindow to show the keypad window, you make a signal in the keypad class and connect it to your new handler:

def main():
   app = QtGui.QApplication(sys.argv)
   home = mainwindow()   #mainwindow object
   keypad = keypad()     #keypad object
   keypad.ui.updated_value.connect(home.keypadHandler) # updated_value show preferably be emitted everytime the value changes
   home.ui.set_btn.clicked.connect(keypad.show)  #keypad window will show if press set_btn
   homewindow.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