Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PyQt5, PySide6 and PyCharm issue
Forum Updated to NodeBB v4.3 + New Features

PyQt5, PySide6 and PyCharm issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 674 Views 1 Watching
  • 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.
  • L Offline
    L Offline
    LMario
    wrote on last edited by
    #1

    I am starting using PySide6. I am using the software in title. I get the following error:

    I developed the UI with Qt 5 designer and then converted it to a .py file.

    Traceback (most recent call last):
      File "/media/soporte/DD Externo/LMario/ITSTA/Carga Académica/AY-Feb-Jul25/Programación Visual/Prácticas Python PySide/HolaMundoEnv/HolaMundo.py", line 23, in <module>
        form = HolaMundo()
      File "/media/soporte/DD Externo/LMario/ITSTA/Carga Académica/AY-Feb-Jul25/Programación Visual/Prácticas Python PySide/HolaMundoEnv/HolaMundo.py", line 15, in __init__
        self.setupUi(self)
      File "/media/soporte/DD Externo/LMario/ITSTA/Carga Académica/AY-Feb-Jul25/Programación Visual/Prácticas Python PySide/HolaMundoEnv/HolaMundoGUI.py", line 18, in setupUi
        self.centralwidget = QtWidgets.QWidget(MainWindow)
    TypeError: QWidget(parent: Optional[QWidget] = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'HolaMundo'
    
    Process finished with exit code 1
    

    The scripts are:

    import os
    import sys
    if sys.platform == "linux":
        # Fixes "undefined symbol: wl_proxy_marshal_flags": https://bugreports.qt.io/browse/QTBUG-114635}}
        os.environ.setdefault("QT_QPA_PLATFORM", "xcb")
    
    from PySide6 import QtWidgets as qtw
    
    from HolaMundoGUI import Ui_MainWindow
    
    class HolaMundo(qtw.QWidget, Ui_MainWindow):
      def __init__(self):
        super().__init__()
    
        self.setupUi(self)
    
        self.show()
    
    if __name__ == "__main__":
    
      app = qtw.QApplication(sys.argv)
    
      form = HolaMundo()
    
      sys.exit(app.exec())
    

    HolaMundoGUI is

    # -*- coding: utf-8 -*-
    # Form implementation generated from reading ui file 'HolaMundoGUI.ui'
    #
    # Created by: PyQt5 UI code generator 5.15.9
    #
    # WARNING: Any manual changes made to this file will be lost when pyuic5 is
    # run again.  Do not edit this file unless you know what you are doing.
    
    from PyQt5 import QtCore, QtGui, QtWidgets
    
    class Ui_MainWindow(object):
        def setupUi(self, MainWindow):
            MainWindow.setObjectName("MainWindow")
            MainWindow.resize(800, 600)
            self.centralwidget = QtWidgets.QWidget(MainWindow)
            self.centralwidget.setObjectName("centralwidget")
            self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.centralwidget)
            self.horizontalLayout_2.setObjectName("horizontalLayout_2")
            self.horizontalLayout = QtWidgets.QHBoxLayout()
            self.horizontalLayout.setObjectName("horizontalLayout")
            self.pushButton = QtWidgets.QPushButton(self.centralwidget)
            self.pushButton.setMaximumSize(QtCore.QSize(100, 30))
            self.pushButton.setObjectName("pushButton")
            self.horizontalLayout.addWidget(self.pushButton)
            self.horizontalLayout_2.addLayout(self.horizontalLayout)
            MainWindow.setCentralWidget(self.centralwidget)
    
            self.retranslateUi(MainWindow)
            QtCore.QMetaObject.connectSlotsByName(MainWindow)
    
        def retranslateUi(self, MainWindow):
            _translate = QtCore.QCoreApplication.translate
            MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
            self.pushButton.setText(_translate("MainWindow", "Aceptar"))
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You HolaMundo a QWidget however from your Ui_MainWindow it's clearly a QMainWindow. You cannot just change the base class like that.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • L Offline
        L Offline
        LMario
        wrote on last edited by
        #3

        Thanks for your help, but I need more guidance.

        Do I need to regenerate HolaMUndoGUI.py in another way or is the problem solved by making changes to the main program?

        Thanks.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The less error prone would be to revert that file back to it's original name and content.
          There's a logic why the UI file and then the generated class share the same name.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • L Offline
            L Offline
            LMario
            wrote on last edited by
            #5

            It is not clear to me what you say since the generated class is called HolaMundo and the UI file HolaMundoGUI.

            JonBJ 1 Reply Last reply
            0
            • L LMario

              It is not clear to me what you say since the generated class is called HolaMundo and the UI file HolaMundoGUI.

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

              @LMario
              I don't know quite what @SGaist is getting at about different names/content. However above all your first file has

              from PySide6 import QtWidgets as qtw
              

              while your second file has

              from PyQt5 import QtCore, QtGui, QtWidgets
              

              What is going on here? Per your title you certainly cannot mix either PyQt and PySide nor anything Qt5 with Qt6.

              SGaistS 1 Reply Last reply
              1
              • JonBJ JonB

                @LMario
                I don't know quite what @SGaist is getting at about different names/content. However above all your first file has

                from PySide6 import QtWidgets as qtw
                

                while your second file has

                from PyQt5 import QtCore, QtGui, QtWidgets
                

                What is going on here? Per your title you certainly cannot mix either PyQt and PySide nor anything Qt5 with Qt6.

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @JonB Good catch !

                As for what I meant: the uic file is clearly for a class named MainWindow and not HolaMundo.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1

                • Login

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