Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. how to include page1.ui file in mainwindow.ui file
QtWS25 Last Chance

how to include page1.ui file in mainwindow.ui file

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 2 Posters 281 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abiabi
    wrote on last edited by abiabi
    #1

    i have a main window created in qt creator.
    its ui file is named mainwindow.ui.
    also i created a frame in another ui file "page1.ui" by qt creator.

    these two files it generated respective .py files automaticaly

    i want to add page1 to main window.
    i tried to add page1 to mainwindow by promote option.
    but it is raising errors when i run it by qt creator.

    my intention is simple. i want to reuse ui files in many places of my software .

    note : iam willing to make small modification to generated py files to make this possible.but i want to design these reusable parts using qt creator/designer

    JonBJ 1 Reply Last reply
    0
    • A abiabi

      i have a main window created in qt creator.
      its ui file is named mainwindow.ui.
      also i created a frame in another ui file "page1.ui" by qt creator.

      these two files it generated respective .py files automaticaly

      i want to add page1 to main window.
      i tried to add page1 to mainwindow by promote option.
      but it is raising errors when i run it by qt creator.

      my intention is simple. i want to reuse ui files in many places of my software .

      note : iam willing to make small modification to generated py files to make this possible.but i want to design these reusable parts using qt creator/designer

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @abiabi
      Promote is the way to do it at design time.
      "but it is raising errors" does not tell anyone much.
      Various references for PyQt/PySide:
      https://stackoverflow.com/questions/4832695/promote-pyqt-widget
      https://www.mail-archive.com/pyqt@riverbankcomputing.com/msg17893.html
      https://forum.qt.io/topic/126277/how-do-i-make-custom-widgets-promote-widgets-for-qt-designer-using-pyside/
      https://forum.pythonguis.com/t/pyside6-promoting-qwidget-to-mplwidget-using-qtdesigner-not-working/1195

      1 Reply Last reply
      2
      • A Offline
        A Offline
        abiabi
        wrote on last edited by abiabi
        #3

        hi.thanks for reply but
        when i created a widget by inheriting from pyside6 widget it canbe used for promote option
        but when i choose a widget that is created using ui file,then it raising errors.not working as expected.

        Traceback (most recent call last):
          File "C:\Users\user\Documents\untitled20\main.py", line 21, in <module>
            widget = main()
                     ^^^^^^
          File "C:\Users\user\Documents\untitled20\main.py", line 16, in __init__
            self.ui.setupUi(self)
          File "C:\Users\user\Documents\untitled20\ui_form.py", line 27, in setupUi
            self.widget = Ui_Form(main)
                          ^^^^^^^^^^^^^
        TypeError: Ui_Form() takes no arguments
        

        iam attaching a simple test project here.

        https://filebin.net/wobwhd8y65pme1cp/test_promote_pyside6.zip

        1 Reply Last reply
        0
        • A Offline
          A Offline
          abiabi
          wrote on last edited by abiabi
          #4

          i think the reason of this error is caused by generated class defnition of page1.ui file.

          the "Ui_Form" class that is generated from page1.ui file is not a qt object. thats maybe the reason why we cant use it in promote option.

          below is that generated code.you can see it is not inherited from qwidget, it is just inherited from Object.

          from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
              QMetaObject, QObject, QPoint, QRect,
              QSize, QTime, QUrl, Qt)
          from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
              QFont, QFontDatabase, QGradient, QIcon,
              QImage, QKeySequence, QLinearGradient, QPainter,
              QPalette, QPixmap, QRadialGradient, QTransform)
          from PySide6.QtWidgets import (QApplication, QPushButton, QSizePolicy, QWidget)
          
          class Ui_Form(object):
              def setupUi(self, Form):
                  if not Form.objectName():
                      Form.setObjectName(u"Form")
                  Form.resize(400, 300)
                  self.pushButton = QPushButton(Form)
                  self.pushButton.setObjectName(u"pushButton")
                  self.pushButton.setGeometry(QRect(110, 100, 97, 30))
          
                  self.retranslateUi(Form)
          
                  QMetaObject.connectSlotsByName(Form)
              # setupUi
          
              def retranslateUi(self, Form):
                  Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None))
                  self.pushButton.setText(QCoreApplication.translate("Form", u"page1 button", None))
              # retranslateUi
          
          
          
          1 Reply Last reply
          0
          • A Offline
            A Offline
            abiabi
            wrote on last edited by
            #5

            i found a wraper code that canbe used for promote option.
            this code inherited from qwidget and it extends ui code. so we can use it for promote option

            https://stackoverflow.com/questions/46284990/promoting-widgets-and-using-them-from-generated-ui

            but why there is no inbuilt option in qt creator for such usecase.

            JonBJ 1 Reply Last reply
            1
            • A abiabi

              i found a wraper code that canbe used for promote option.
              this code inherited from qwidget and it extends ui code. so we can use it for promote option

              https://stackoverflow.com/questions/46284990/promoting-widgets-and-using-them-from-generated-ui

              but why there is no inbuilt option in qt creator for such usecase.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @abiabi
              Because Qt Designer/Creator is not particularly Python-oriented.
              The accepted solution from @eyllanesc is the way to go, as with his other Python posts.

              1 Reply Last reply
              1
              • A abiabi has marked this topic as solved on

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved