PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 244 - load of QUiLoader don't work with custom class
: load of QUiLoader don't work with custom class
Status: CLOSED INVALID
Product: PySide
Classification: Unclassified
Component: QtUiTools
: 0.3.1
: PC Linux
: P5 critical
Assigned To: renato filho
:
:
:
  Show dependency treegraph
 
Reported: 2010-06-14 12:54 EEST by mancausoft
Modified: 2010-08-13 11:29 EEST (History)
7 users (show)

See Also:


Attachments
file ui (3.53 KB, application/octet-stream)
2010-07-07 11:15 EEST, mancausoft
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mancausoft 2010-06-14 12:54:28 EEST
QUiLoader().load don't work with my custom class, but return a new QMainWindow
instance.

class MainWidget(QMainWindow):
    def __init__(self):
        super(MainWidget, self).__init__()

if __name__ == '__main__':
    import sys
    QApplication.setDesktopSettingsAware(False)
    app = QApplication(sys.argv)
    widget = MainWidget()
    print QUiLoader().load("./file.ui", widget)
    print widget
    widget.show()
    sys.exit(app.exec_())

Why the result is: 
<PySide.QtGui.QMainWindow object at 0x9a88fa0>
<__main__.MainWidget object at 0x9a82e6c>
Comment 1 Hugo Parente Lima 2010-07-07 10:58:41 EEST
Can you attach your .ui file?
Comment 2 mancausoft 2010-07-07 11:15:12 EEST
Created attachment 53 [details]
file ui
Comment 3 Hugo Parente Lima 2010-07-07 15:14:26 EEST
I got the same behaviour in the C++ version:

#include <QtGui>
#include <QtUiTools>

class MainWidget : public QMainWindow
{
};

int main(int argc, char** argv)
{
    QApplication app(argc, argv);
    MainWidget wdg;

    QUiLoader loader;
    QFile file("file.ui");
    file.open(QIODevice::ReadOnly);
    loader.load(&file, &wdg);
    wdg.show();

    return app.exec();
}


When using a .ui file with a QMainWindow widget is better to use the pyside-uic
approach than the QUiTools approach.

The problem is: QUiLoader.load() will already return a QMainWindow, so you
don't have to inherit your class (MainWidget) from QMainWindow.

This modified version of your example works correctly:

from PySide.QtGui import *
from PySide.QtUiTools import *

class MainWidget:
    pass

if __name__ == '__main__':
    import sys
    QApplication.setDesktopSettingsAware(False)
    app = QApplication(sys.argv)
    widget = MainWidget()
    widget.mainWindow = QUiLoader().load("./file.ui", None)
    widget.mainWindow.show()
    sys.exit(app.exec_())

Btw I'll modify the signature of QUiLoader.load(str, QWidget) to
QUiLoader.load(str, QWidget = None)