Details
-
Bug
-
Resolution: Fixed
-
Not Evaluated
-
Qt Creator 4.15.0
-
None
-
-
c4f6fd5dd (master)
Description
Hello!
I've tried using Qt Creator to design my UI file using PySide6.
The project wizard generated a ui file alongside a class in Python (extending QMainWindow).
The problem is that even if the code correctly loads the UI file, once executed the class will show() an empty widget, with the default (python file name) title.
Digging in the documentation it seems that the QUiLoader.load method returns a QWidget: the generated code though doesn't handle that output variable, throwing the load process away.
I've currently set a local variable and overwritten the show() method (follows the code), even if I'm not sure whether I'd handle in that way, or in a better one.
Thanks
# This Python file uses the following encoding: utf-8 import os from pathlib import Path import sys from PySide6.QtWidgets import QApplication, QMainWindow, QWidget from PySide6.QtCore import QFile from PySide6.QtUiTools import QUiLoader class MainWindow(QMainWindow): ui: QWidget # change here def __init__(self) -> None: super(MainWindow, self).__init__() self.load_ui() def load_ui(self) -> None: loader = QUiLoader() path = os.fspath(Path(__file__).resolve().parent / 'form.ui') ui_file = QFile(path) ui_file.open(QFile.ReadOnly) self.ui = loader.load(ui_file, self) # change here ui_file.close() def show(self) -> None: # change here return self.ui.show() if __name__ == "__main__": app = QApplication([]) widget = MainWindow() widget.show() sys.exit(app.exec())
Attachments
For Gerrit Dashboard: QTCREATORBUG-25807 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
452385,5 | Python: Remove wizard for dynamically loaded ui projects | master | qt-creator/qt-creator | Status: MERGED | +2 | 0 |