Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
# This Python file uses the following encoding: utf-8
import os
from pathlib import Path
import sys
from PySide2.QtWidgets import QApplication, QMainWindow
from PySide2.QtCore import QFile
from PySide2.QtUiTools import QUiLoader
from PySide2 import QtCore
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_DontCheckOpenGLContextThreadAffinity)
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts)
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.load_ui()
def load_ui(self):
path = os.fspath(Path(__file__).resolve().parent / "mainwindow.ui")
ui_file = QFile(path)
ui_file.open(QFile.ReadOnly)
loader = QUiLoader()
loader.load(ui_file, self)
ui_file.close()
if __name__ == "__main__":
app = QApplication([])
main = MainWindow()
main.show()
sys.exit(app.exec_())
Damit bekomme ich aber immer nur ein kleines, leeres Fenster angezeigt und nicht mein "mainwindow.ui", welches ich mit dem QtDesigner erstellt habe.
Kann jemand helfen?
QUiLoader.load liefert ein widget, mit dem Du aber nichts machst.
Wenn die Datei mainwindow.ui heißt, ist da wahrscheinlich ein komplettes QMainWindow definiert:
Super! Vielen Dank für die schnelle Hilfe!
Manchmal ist die (Python)Welt mit Brettern vernagelt...
Jetzt läuft es erstmal, wie ich es mir vorgestellt habe.
Nochmals Danke.
Traceback (most recent call last):
File "/Users/wernerbarz/PycharmProjects/MissionCreator_neu/mainwindow_neu.py", line 35, in <module>
main()
File "/Users/wernerbarz/PycharmProjects/MissionCreator_neu/mainwindow_neu.py", line 30, in main
my_main.label_quickView.setText("Hallo Welt")
AttributeError: 'MainWindow' object has no attribute 'label_quickView'
Process finished with exit code 1