May 2019
Intermediate to advanced
542 pages
13h 37m
English
A combobox, also known as a dropdown or select widget, is a widget that presents a list of options when clicked on, one of which must be selected. QCombobox can optionally allow text input for custom answers by setting its editable property to True.
Let's create a QCombobox object like so:
combobox = qtw.QComboBox(self)
Right now, our combobox has no items in its menu. QCombobox doesn't provide a way to initialize the widget with options in the constructor; instead, we have to create the widget, then use the addItem() or insertItem() method to populate its menu with options, like so:
combobox.addItem('Lemon', 1) combobox.addItem('Peach', 'Ohh I like Peaches!') combobox.addItem('Strawberry', qtw.QWidget) combobox.insertItem(1, ...Read now
Unlock full access