[PyQt] mainwindow and dialog question

Jason Rahm J.Rahm at F5.com
Mon Mar 28 12:48:57 BST 2011


Python 2.7.1 / PyQt 4.8.3 / Qt 4.7.2

I have a mainwindow and a dialog designed in Qt Designer and converted to python code via pyuic4:

Mainwindow - Ui_editor.py (class is Ui_mw_editor)
Dialog1 - Ui_connect.py (class is Ui_dia_connect)

I have a menubar with actions defined in the Qt Designer (code from Ui_editor.py):

        self.actionConnect = QtGui.QAction(mw_Editor)
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap(_fromUtf8("icons/default/ToolbarConnect.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionConnect.setIcon(icon2)
        self.actionConnect.setObjectName(_fromUtf8("actionConnect"))

So, from my app.py file, I have this code:

import os, sys
from PyQt4 import QtCore
from PyQt4.QtGui import QMainWindow, QDialog, QApplication

from ui.Ui_Editor import Ui_mw_Editor
from ui.Ui_connect import Ui_dia_connect

class Main(QMainWindow, Ui_mw_Editor):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setupUi(self)
        self.actionConnect.connect(self.connectDialog)

    def connectDialog(self):
                self.connectdlg = ConnectDlg()
                self.connectdlg.show()

class ConnectDlg(QDialog, Ui_dia_connect):
                def __init__(self):
                                QDialog.__init__(self)
                                self.setupUi(self)
                                self.actionConnect.connect(self.close)

def main():

    app = QApplication(sys.argv)
    window=Main()
    window.show()
    sys.exit(app.exec_())


if __name__ == "__main__":
    main()


###

If I remove the self.actionConnect.connect(self.connectDialog) and the supporting def and class, the mainwindow launches OK.  If I include it, I get these errors:

D:\dev\f5editor>python mw2.py
Traceback (most recent call last):
  File "mw2.py", line 42, in <module>
    main()
  File "mw2.py", line 35, in main
    window=Main()
  File "mw2.py", line 18, in __init__
    self.actionConnect.connect(self.connectDialog)
TypeError: arguments did not match any overloaded call:
  QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'instancemethod'
  QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'instancemethod'
  QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'instancemethod'


Any help would be appreciated.

Jason

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110328/31408099/attachment.html>


More information about the PyQt mailing list