How to implement dialogs within a mainwindow class designed in QtDesigner?
I'm writing a small app (learning Python and PyQt) that has an "About" box. I've designed the QMainWindow in QtDesigner and managed to make it work. I've also designed the About box in the QtDesigner as a dialog.
I used pyuic4 to convert both .ui files to .py files, the main.py and about-dialog.py
However, how do I "call" the about dialog from the main app? What should the function look like? I tried putting:
dialog = ui_aboutDialog.Ui_aboutDlg()
dialog.exec_()
However, it gives me that about dialog has no "exec" attribute (same for .show()).
Here is the beginning of the aboutDialog class:
class Ui_aboutDlg(object):
def setupUi(self, aboutDlg):
aboutDlg.setObjectName(_fromUtf8("aboutDlg"))
aboutDlg.resize(400, 262)
...
I think something is wro开发者_如何学Cng with this setupUi and that it should rather be __init__, but trying that yielded no results either.
Help?
Read the tutorial carefully. The pyuic4 tool won't make a full dialog for you; it'll only provide a method that sets up an already existing dialog.
dialog = QtGui.QDialog()
ui = ui_aboutDialog.Ui_aboutDlg()
ui.setupUi(dialog)
dialog.exec_()
精彩评论