Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

pyside2-uic (5.14) problem with custom classes



  • Hello Everyone,

    Yesterday I updated pyside2 from 5.11 to 5.14 using pip.

    When I tried to generate *.py files from the *.ui files I stumbled into a problem. It seems that the latest version is not handling properly the custom classes.

    For instance if I have a simple ui file (the file that contains the custom class is named 'power_table.py'):

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>TableViewer</class>
     <widget class="QDialog" name="TableViewer">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>964</width>
        <height>300</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>Table Viewer</string>
      </property>
      <layout class="QGridLayout" name="gridLayout">
       <item row="0" column="1">
        <widget class="QDialogButtonBox" name="buttonBox">
         <property name="orientation">
          <enum>Qt::Vertical</enum>
         </property>
         <property name="standardButtons">
          <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
         </property>
        </widget>
       </item>
       <item row="0" column="0">
        <widget class="PowerTableView" name="view_widget" native="true"/>
       </item>
      </layout>
     </widget>
     <customwidgets>
      <customwidget>
       <class>PowerTableView</class>
       <extends>QWidget</extends>
       <header>power_table</header>
      </customwidget>
     </customwidgets>
     <resources/>
     <connections>
      <connection>
       <sender>buttonBox</sender>
       <signal>accepted()</signal>
       <receiver>TableViewer</receiver>
       <slot>accept()</slot>
       <hints>
        <hint type="sourcelabel">
         <x>248</x>
         <y>254</y>
        </hint>
        <hint type="destinationlabel">
         <x>157</x>
         <y>274</y>
        </hint>
       </hints>
      </connection>
      <connection>
       <sender>buttonBox</sender>
       <signal>rejected()</signal>
       <receiver>TableViewer</receiver>
       <slot>reject()</slot>
       <hints>
        <hint type="sourcelabel">
         <x>316</x>
         <y>260</y>
        </hint>
        <hint type="destinationlabel">
         <x>286</x>
         <y>274</y>
        </hint>
       </hints>
      </connection>
     </connections>
    </ui>
    
    

    and use pyside2-uic (v5.14) for generating the repective .py file I get:

    from PySide2.QtCore import (QCoreApplication, QMetaObject, QObject, QPoint,
        QRect, QSize, QUrl, Qt)
    from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QFont,
        QFontDatabase, QIcon, QLinearGradient, QPalette, QPainter, QPixmap,
        QRadialGradient)
    from PySide2.QtWidgets import *
    
    import PowerTableView
    
    class Ui_TableViewer(object):
        def setupUi(self, TableViewer):
            if TableViewer.objectName():
                TableViewer.setObjectName(u"TableViewer")
            TableViewer.resize(964, 300)
            self.gridLayout = QGridLayout(TableViewer)
            self.gridLayout.setObjectName(u"gridLayout")
            self.buttonBox = QDialogButtonBox(TableViewer)
            self.buttonBox.setObjectName(u"buttonBox")
            self.buttonBox.setOrientation(Qt.Vertical)
            self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
    
            self.gridLayout.addWidget(self.buttonBox, 0, 1, 1, 1)
    
            self.view_widget = PowerTableView(TableViewer)
            self.view_widget.setObjectName(u"view_widget")
    
            self.gridLayout.addWidget(self.view_widget, 0, 0, 1, 1)
    
    
            self.retranslateUi(TableViewer)
            self.buttonBox.accepted.connect(TableViewer.accept)
            self.buttonBox.rejected.connect(TableViewer.reject)
    
            QMetaObject.connectSlotsByName(TableViewer)
        # setupUi
    
        def retranslateUi(self, TableViewer):
            TableViewer.setWindowTitle(QCoreApplication.translate("TableViewer", u"Table Viewer", None))
        # retranslateUi
    

    but when I use 5.11 version I get:

    from PySide2 import QtCore, QtGui, QtWidgets
    
    class Ui_TableViewer(object):
        def setupUi(self, TableViewer):
            TableViewer.setObjectName("TableViewer")
            TableViewer.resize(964, 300)
            self.gridLayout = QtWidgets.QGridLayout(TableViewer)
            self.gridLayout.setObjectName("gridLayout")
            self.buttonBox = QtWidgets.QDialogButtonBox(TableViewer)
            self.buttonBox.setOrientation(QtCore.Qt.Vertical)
            self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
            self.buttonBox.setObjectName("buttonBox")
            self.gridLayout.addWidget(self.buttonBox, 0, 1, 1, 1)
            self.view_widget = PowerTableView(TableViewer)
            self.view_widget.setObjectName("view_widget")
            self.gridLayout.addWidget(self.view_widget, 0, 0, 1, 1)
    
            self.retranslateUi(TableViewer)
            QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), TableViewer.accept)
            QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), TableViewer.reject)
            QtCore.QMetaObject.connectSlotsByName(TableViewer)
    
        def retranslateUi(self, TableViewer):
            TableViewer.setWindowTitle(QtWidgets.QApplication.translate("TableViewer", "Table Viewer", None, -1))
    
    from power_table import PowerTableView
    

    Any ideas?


  • Lifetime Qt Champion

    Hi,

    Indeed, it looks like something is wrong. Can you check with previous versions of PySide2 to see where exactly it changed ?



  • Hello SGaist!

    I will check with whatever is available on pip from version 5.11.

    Thanks!



  • Ok SGaist,

    I can confirm that everything works fine until version 5.13.2, that is, the one previous to 5.14 (on pip at least)


  • Lifetime Qt Champion

    You may have found a bug :-)
    Please check the bug report system to see if it's something known and if not please open a new report with your findings.


Log in to reply