-2

I have a PyQt6 GUI created with QT Designer

I load the GUI .ui file into python as follows:

class UI(QMainWindow):
    def __init__(self):
        super().__init__()

        self.threadpool = QThreadPool()

        # loading the ui file with uic module
        uic.loadUi("menu.ui", self)

        # DEFINE WIDGETS
        self.testlabel = self.findChild(QLabel, "testlabel")
        self.testlabel.setText("CHANGE TEXT)
        
app = QApplication([])
window = UI()
window.show()
app.exec()

The GUI works great Under #DEFINE WIDGETS I can change the text of the testlabel in the GUI after loading the ui into Python

Now my question

I have a QComboBox with 5 items in the GUI called : widget class="QComboBox" name="emulatorListComboBox"

How do I change list box items the same way after loading the GUI into Python?

I don't want to change them in the menu.ui file as they will keep changing daily

musicamante
  • 41,230
  • 6
  • 33
  • 58
OK Tech
  • 1
  • 1
  • Just study the documentation: [`clear()`](https://doc.qt.io/qt-5/qcombobox.html#clear), [`addItem()`](https://doc.qt.io/qt-5/qcombobox.html#addItem), [`addItems()`](https://doc.qt.io/qt-5/qcombobox.html#addItems), and so on. Also, using uic there's really no need for `findChild()`: `self.testlabel` already exists at that point, as it was created by `loadUi`. – musicamante Jul 03 '23 at 05:18
  • You should add the solution as an answer and mark it as accepted. :^) – doneforaiur Jul 03 '23 at 05:25

1 Answers1

0

Replace the 2nd item in ListComboBox:

self.List = self.findChild(QComboBox, "ListComboBox")

self.List.insertItem(2,"TEST")

OK Tech
  • 1
  • 1