I've installed Qt Creator v9.0.1 on Ubuntu 22.04 / Windows 10 and try to create a new project which shows an empty frame and not the loaded form.ui
:
Testcase:
Default generated mainwindow.py:
# This Python file uses the following encoding: utf-8
import os
from pathlib import Path
import sys
from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtCore import QFile
from PySide6.QtUiTools import QUiLoader
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.load_ui()
def load_ui(self):
loader = QUiLoader()
path = Path(__file__).resolve().parent / "form.ui"
ui_file = QFile(path)
ui_file.open(QFile.ReadOnly)
loader.load(ui_file, self)
ui_file.close()
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = MainWindow()
widget.show()
sys.exit(app.exec())
Default generated form.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar"/>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
I expected the form.ui
window size with menubar and statusbar instead of an empty small window. Same behavior on Windows and Ubuntu 22.04 Any suggestion?
Qt bug report: https://bugreports.qt.io/browse/QTCREATORBUG-25807.
Problem solved as this is a bug in Qt Creator when creating a New Project with dynamic load and QMainWindow
base class:
# This Python file uses the following encoding: utf-8
import os
from pathlib import Path
import sys
from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtCore import QFile
from PySide6.QtUiTools import QUiLoader
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.load_ui()
def load_ui(self):
loader = QUiLoader()
path = Path(__file__).resolve().parent / "form.ui"
ui_file = QFile(path)
ui_file.open(QFile.ReadOnly)
- loader.load(ui_file, self)
+ widget = loader.load(ui_file, self)
ui_file.close()
+ widget.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = MainWindow()
- # widget.show()
sys.exit(app.exec())