0

Im using Pyside6 with pyqt6 on Qt designer. I just tried to make a basic pushbutton (which does nothing) inside a grid layout inside the main window on the Qt designer. I saved that file in ui format and converted into python file using the uic.exe present in the pyside6 library. So the problem is that this pyside6 uic.exe converter gives the python file with only classes and objects and by following some threads on stack overflow, I used the window.show() method and it says AttributeError: 'Ui_MainWindow' object has no attribute 'show'. I dont know how to get the output and I dont know what function I need to call to get the output.

Here is the code generated by uic.exe in pyside6

# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'testing1.ui'
##
## Created by: Qt User Interface Compiler version 6.4.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

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, QGridLayout, QMainWindow, QMenuBar,
    QPushButton, QSizePolicy, QStatusBar, QWidget)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(842, 643)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.gridLayoutWidget = QWidget(self.centralwidget)
        self.gridLayoutWidget.setObjectName(u"gridLayoutWidget")
        self.gridLayoutWidget.setGeometry(QRect(10, 20, 801, 561))
        self.gridLayout = QGridLayout(self.gridLayoutWidget)
        self.gridLayout.setObjectName(u"gridLayout")
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.pushButton = QPushButton(self.gridLayoutWidget)
        self.pushButton.setObjectName(u"pushButton")

        self.gridLayout.addWidget(self.pushButton, 0, 0, 1, 1)

        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 842, 22))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)
    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
        self.pushButton.setText(QCoreApplication.translate("MainWindow", u"PushButton", None))
    # retranslateUi


#the below code is written by me seeing the other stackoverflow question related to this issue

app = QApplication([])
window = Ui_MainWindow()
window.show()
app.exec()

[This shows the Qt designer ](https://i.stack.imgur.com/UZ2pc.png)

The thing is that I want this python program to show some output like the window shown in the Qt designer. Any help would be awesome. As im a beginner in both pyqt6 and Qt designer kindly elobrate the answer please.

  • That class is just a basic python object, and is a "helper" class that you must use along with an actual Qt class (QMainWindow, in your case). Follow the answers for the post marked as duplicated, and also follow the guidelines about [using Designer](//www.riverbankcomputing.com/static/Docs/PyQt6/designer.html), while it's for PyQt, but the concepts are the same, just change the import statements. – musicamante Feb 25 '23 at 16:12
  • 2
    Does this answer your question? [QObject has no attribute 'show'](https://stackoverflow.com/questions/19453934/qobject-has-no-attribute-show) Also https://stackoverflow.com/questions/27112396/pyqt-ui-form-object-has-no-attribute-show and https://stackoverflow.com/questions/46544780/qtdesigner-changes-will-be-lost-after-redesign-user-interface – musicamante Feb 25 '23 at 16:13

1 Answers1

0
app = QApplication([])
window = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(window)
window.show()
app.exec()

this is the part of the code that I was missing thanks guys for helping me.

this code works with pyqt6 and pyside6 to view your window that you designed in qtdesigner with the python file generated by uic.exe inside the python IDE.

  • When a duplicate suggestion is made, please consider to accept it (there should be a specific button that would appear in the question) instead of creating another answer. Also, please take your time to follow the [tour], read [ask] and [answer], and remember that we try to limit as much as possible posts that are clear duplicates of existing questions and related answers. – musicamante Feb 28 '23 at 00:12