[英]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. 我正在使用pyqt来构建gui,使用来自qt Designer的.UI文件,然后通过pyuic4进行转换。
I have two windows, 我有两个窗户
1st - mainwindow (which has some label and buttons) 1st-主窗口(有一些标签和按钮)
2nd - Window is a numeric keypad input window. 2nd-窗口是数字小键盘输入窗口。
I have the .py of the UI file seperate and load it in main program by 我将UI文件的.py分开并通过以下方式将其加载到主程序中
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. 当我单击主窗口中的按钮时,应打开num键盘窗口。 (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. 这似乎是一个简单的问题,但是我找不到plz帮助我。
*is there any existing method for keypad operations, in qtdesigner or pyqt?? *在qtdesigner或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: 在您的mainwaindow中 ,定义处理程序:
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_())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.