I'm trying to program a quick dialog with QT4 and Python. I've generated the Python class, using pyuic4, and tried to make a small python script to start it up:
import sys
from PyQt4 import QtCore, QtGui
from ConfigGUI import Ui_ConfigGUI
class StartQT4(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_ConfigGUI()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = StartQT4()
myapp.show()
sys.exit(app.exec_())
When I try to run it, it says AttributeError: 'StartQT4' object has no attribute 'accept'.
What did I do wrong?
I managed to reproduce your problem. You selected a form based on dialogs in the QtDesigner, but are trying to construct it inside a QMainWindow.

The UI code tries to bind its buttons to default dialog slots acceptand reject which are not available in a QMainWindow.
From ConfigGUI.py:
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Dialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject)
The class contains a method called
setupUi(). This takes a single argument which is the widget in which the user interface is created. The type of this argument (typicallyQDialog,QWidgetorQMainWindow) is set in Designer. We refer to this type as the Qt base class.-- http://pyqt.sourceforge.net/Docs/PyQt4/designer.html
So, either select Main Window in the Designer as a base class, or change the inheritance of StartQT4 to QtGui.QDialog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With