-
Notifications
You must be signed in to change notification settings - Fork 0
What We Know About QComboBox with Strings
Table of Contents
A QComboBox is a drop-down list box (also known as a combo box or DDL) used in GUI applications to let the user select one item from a list. Combo boxes may also support editing, allowing users to type in values that are not in the list.
There are two general types one uses strings to populate the QComboBox, the other uses a Model. This documentation is for a QComboBox driven by a strings. ( for the type based on a Model see What We Know About QComboBox with Model
This tab demonstrates and documents the use of the QComboBox widget in a QTPY application. Two combo boxes are used and controlled by several methods that mutate their appearance and behavior.
The key points:
- When clicked, combo boxes expand to show their entire list of values.
- When one item on the list is clicked, combo boxes shrink to show only the one selected value.
- They can be editable, meaning the user can type new values.
- They emit signals when the user changes selection or enters text.
- They can be modified at runtime, with items added, removed, or reloaded.
Like other tabs in this application, this is a reference tab, showing expected widget behavior and tab structure.
📄 Code file:
qt5_by_example/tabs/basic_widgets/tab_q_combo_box.py
💡 View it in your IDE for full effect.
The documentation includes detailed comments in _build_gui_widgets() and the various mutate_ methods. This is part of the tab documentation pattern used throughout the project. See also: Tab Framework Code.
Try the following actions on this tab:
- Use the dropdown in combo_1 to select values from a predefined list.
- In combo_2, type a custom value and press Enter.
- Press the "combo\n_reload" button to clear and reload
combo_1. - Use the mutate button to explore different programmatic changes to the combo boxes.
- Observe the signal messages logged in the text area below the widgets.
- Use Inspect to examine internal state.
-
combo_1is a static dropdown list. -
combo_2is editable, supporting typed input. - Text changes and index changes trigger signal handlers.
- Mutate methods alter content, selection, or visibility.
- You can inspect widget properties via
mutate_3()andinspect().
Initializes two combo boxes:
-
combo_1is filled with static items and starts with"Two"selected. -
combo_2is editable and also preloaded with values. - Both combo boxes are connected to
currentIndexChangedandcurrentTextChangedhandlers. - Adds a reload button and other standard controls.
- Modifies
combo_2using.lineEdit().setText(). - Logs the current text of
combo_1.
- Sets values for `combo