Search code examples
pythonqtpyqt4attributeerror

Atribute Error PyQt4 no attribute 'setFrameShape'


Hello I have a problem with PyQt4.

I created an simple Project in the Qt Designer, but I can't run it. I tried some codes an changed a lot, but I get the same Error every time: AttributeError: 'MyApp' object has no attribute 'setFrameShape'

So thats my code to run the .py code, with I converted from the .ui:

import sys
from PyQt4 import QtGui
from qt_test import Ui_Frame


class Example(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_Frame()
        self.ui.setupUi(self)


def main():
    app = QtGui.QApplication(sys.argv)
    form = Example()
    form.show()
    sys.exit(app.exec_())


main()

And here is the Code from qt_test.py with I converted from the .ui file:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'qt_test.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Frame(object):
    def setupUi(self, Frame):
        Frame.setObjectName(_fromUtf8("Frame"))
        Frame.resize(493, 451)
        Frame.setFrameShape(QtGui.QFrame.StyledPanel)
        Frame.setFrameShadow(QtGui.QFrame.Raised)
        self.verticalLayout = QtGui.QVBoxLayout(Frame)
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
        self.listWidget = QtGui.QListWidget(Frame)
        self.listWidget.setObjectName(_fromUtf8("listWidget"))
        self.verticalLayout.addWidget(self.listWidget)
        self.pushButton = QtGui.QPushButton(Frame)
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.verticalLayout.addWidget(self.pushButton)

        self.retranslateUi(Frame)
        QtCore.QMetaObject.connectSlotsByName(Frame)

    def retranslateUi(self, Frame):
        Frame.setWindowTitle(_translate("Frame", "Frame", None))
        self.pushButton.setText(_translate("Frame", "PushButton", None))

So thanks if some one could help me, Justus


Solution

  • Based on other answers here, I'd say you're trying to push a QFrame design into a QMainWindow. Also, "Example" class inherite from QMainWindow but the QWidget constructor is the one called, which is weird.