pythonpython-3.xpyside2uic

PySide2-uic generates increasing item index for unrelated widgets


I have a question regarding pyside2-uic as it seems to generate faulty code. First off, is there no way to disable the translation in Qt Designer? It's a pain to disable the translateable checkbox for every string and I find the retranslateUi code a bit messy.

Now to the real issue: as you can see, pyside2-uic seems to increase the item position count even for unrelated widgets. If I create a subclass and execute it, combo-boxes like combox_wb do not carry the default values as the items 7-9 probably dont exist and probably should be 0-2. (I know you could just leave them empty and do the setup manually inside the class that inherits from the uic generated one).

def retranslateUi(self, MainWindow):
    self.gbox_settings.setTitle(QtWidgets.QApplication.translate("MainWindow", "settings", None, -1))
    self.combox_colorspace.setItemText(0, QtWidgets.QApplication.translate("MainWindow", "0   Raw color (unique to each camera)", None, -1))
    self.combox_colorspace.setItemText(1, QtWidgets.QApplication.translate("MainWindow", "1   sRGB D65 (default)", None, -1))
    self.combox_colorspace.setItemText(2, QtWidgets.QApplication.translate("MainWindow", "2   Adobe RGB (1998) D65", None, -1))
    self.combox_colorspace.setItemText(3, QtWidgets.QApplication.translate("MainWindow", "3   Wide Gamut RGB D65", None, -1))
    self.combox_colorspace.setItemText(4, QtWidgets.QApplication.translate("MainWindow", "4   Kodak ProPhoto RGB D65", None, -1))
    self.combox_colorspace.setItemText(5, QtWidgets.QApplication.translate("MainWindow", "5   XYZ", None, -1))
    self.combox_colorspace.setItemText(6, QtWidgets.QApplication.translate("MainWindow", "6   ACES", None, -1))
    self.combox_wb.setItemText(7, QtWidgets.QApplication.translate("MainWindow", "ignore camera white balance", None, -1))
    self.combox_wb.setItemText(8, QtWidgets.QApplication.translate("MainWindow", "use camera white balance", None, -1))
    self.combox_wb.setItemText(9, QtWidgets.QApplication.translate("MainWindow", "specify  own raw white balance", None, -1))
    self.combox_gamma.setItemText(10, QtWidgets.QApplication.translate("MainWindow", "linear", None, -1))
    self.combox_gamma.setItemText(11, QtWidgets.QApplication.translate("MainWindow", "sRGB", None, -1))
    self.combox_bitdepth.setItemText(12, QtWidgets.QApplication.translate("MainWindow", "16-bit", None, -1))
    self.combox_bitdepth.setItemText(13, QtWidgets.QApplication.translate("MainWindow", "8-bit", None, -1))
    self.tbtn_dcrawexec.setText(QtWidgets.QApplication.translate("MainWindow", "...", None, -1))

Solution

  • This is caused by a bug in PySide. The same ui file will work as expected when using PyQt or the old PySide (i.e. the indexing re-starts at zero for each widget). Looking at the code for pyside2uic/uiparser.py shows that they use a shared attribute (self.item_nr) for indexing - but it only ever gets reset to zero for tree-widgets.

    I suggest you create a bug report.