Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1210

PySide2-uic does not call setObjectName() properly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 5.14.0
    • PySide
    • None
    • Windows
    • 6baed766545f1ba5c747a067bb8e324f2bb9681a (qt/qtbase/5.14)

    Description

      I think that PySide2-uic does not call setObjectName() properly when following instructions:
      https://doc.qt.io/qtforpython/tutorials/basictutorial/uifiles.html#generating-a-python-class

      Within Qt Designer I set QObject->objectName value of to NamedMainWindow.
      Later, within python code I would like to access it with objectName(), but I receive empty string:

      class MainWindow(QMainWindow):
          def __init__(self):
              super(MainWindow, self).__init__()
              self.ui = Ui_NamedMainWindow()
              self.ui.setupUi(self)
              print(self.objectName())  # Prints empty string
      

      I have looked at generated ui*.py_ files.
      After using pyside2-uic in version 5.14.0 and 5.14.1, the resulting code fragment is:

      class Ui_NamedMainWindow(object):
          def setupUi(self, NamedMainWindow):
              if NamedMainWindow.objectName():  # Here objectName() is ''
                  NamedMainWindow.setObjectName(u"NamedMainWindow")  # This line is never executed
              # ...

      However, using version 5.13.2 of PySide2 the result is:

      class Ui_NamedMainWindow(object):
          def setupUi(self, NamedMainWindow):
              NamedMainWindow.setObjectName("NamedMainWindow")
              # ...

      which properly sets the Qt object name.

      The issue seems to be a BUG to me.

      I have attached all source files.

      Attachments

        1. main.py
          0.6 kB
        2. mainwindow.ui
          0.7 kB
        3. ui_mainwindow_5_13_2.py
          1 kB
        4. ui_mainwindow_5_14_0.py
          2 kB
        5. ui_mainwindow_5_14_1.py
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kleint Friedemann Kleint
            mlewand3 Marcin Lewandowski
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes