[Python] PySide6 QComboBox.setCurrentIndex() not working as documented

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am attempting to populate a PySide6 combo-box, then set the current index based on the contents of the combo-box.

    def populate_fields_from_args(self):
    for available_report in self.available_reports:
    self.window.comboBoxReportSelector.addItem(available_report['report_name'])
    selected_report_name = [report['report_name'] for report in self.available_reports if report['report_short_name'] == self.args.report][0]
    report_index = self.window.comboBoxReportSelector.findText(str(selected_report_name))
    self.window.comboBoxReportSelector.setCurrentIndex(report_index)


    I am receiving the following error:

    self.window.comboBoxReportSelector.setCurrentIndex(report_index)
    TypeError: descriptor 'setCurrentIndex' for 'PySide6.QtWidgets.QComboBox' objects doesn't apply to a 'int' object


    This makes no sense to me as I have reviewed the documentation for PySide6.QtWidgets.QComboBox.setCurrentIndex and it does indeed take an integer. Additionally I tried this with setCurrentText and received a similar error regarding using a 'str' object.

    To add insult to injury, when I run this exact same code using the PyCharm debugger on MacOS it works, but not using the PyCharm debugger on Linux.

    Any thoughts would be appreciated.

    Continue reading...

Compartilhe esta Página