Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-25807

PySide6 generated class doesn't load UI file correctly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • Qt Creator 10.0.0
    • Qt Creator 4.15.0
    • Python Support
    • None
    • Linux/X11
    • 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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            davschul David Schulz
            jim87 Giacomo Furlan
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes