how to include page1.ui file in mainwindow.ui file
-
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
-
@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 -
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
-
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
-
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 optionhttps://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.
-