python - QDialog not opening from Main window (pyQt) -
python - QDialog not opening from Main window (pyQt) -
i'm trying launch dialog clicking button in main window: here's (qtdesigner generated) code modified test .. i've set showdial function show dial when button clicked. doesn't work :
from pyqt4 import qtcore, qtgui try: _fromutf8 = qtcore.qstring.fromutf8 except attributeerror: _fromutf8 = lambda s: s class ui_dialog(object): def setupui(self, dialog): dialog.setobjectname(_fromutf8("dialog")) dialog.setwindowmodality(qtcore.qt.windowmodal) dialog.resize(400, 300) dialog.setwindowtitle(qtgui.qapplication.translate("dialog", "dialog", none, qtgui.qapplication.unicodeutf8)) self.retranslateui(dialog) qtcore.qmetaobject.connectslotsbyname(dialog) def retranslateui(self, dialog): pass class ui_mainwindow(object): def setupui(self, mainwindow): mainwindow.setobjectname(_fromutf8("mainwindow")) mainwindow.resize(309, 148) mainwindow.setwindowtitle(qtgui.qapplication.translate("mainwindow", "mainwindow", none, qtgui.qapplication.unicodeutf8)) self.centralwidget = qtgui.qwidget(mainwindow) self.centralwidget.setobjectname(_fromutf8("centralwidget")) self.pushbutton = qtgui.qpushbutton(self.centralwidget) self.pushbutton.setgeometry(qtcore.qrect(50, 30, 191, 71)) self.pushbutton.settext(qtgui.qapplication.translate("mainwindow", "open dialog", none, qtgui.qapplication.unicodeutf8)) self.pushbutton.setobjectname(_fromutf8("pushbutton")) mainwindow.setcentralwidget(self.centralwidget) self.retranslateui(mainwindow) qtcore.qobject.connect(self.pushbutton, qtcore.signal(_fromutf8("clicked(qabstractbutton*)")), self.showdial) qtcore.qmetaobject.connectslotsbyname(mainwindow) def retranslateui(self, mainwindow): pass def showdial(self): dialog = qtgui.qdialog() u = ui_dialog() u.setupui(dialog) dialog.exec_() if __name__ == "__main__": import sys app = qtgui.qapplication(sys.argv) mainwindow = qtgui.qmainwindow() ui = ui_mainwindow() ui.setupui(mainwindow) mainwindow.show() sys.exit(app.exec_())
there error in signal connection, should be:
qtcore.qobject.connect(self.pushbutton, qtcore.signal(_fromutf8("clicked()")), self.showdial)
or in more pythonic new-style signal , slot syntax pyqt 4.5+:
self.pushbutton.clicked.connect(self.showdial)
python qt dialog pyqt qdialog
Comments
Post a Comment