Class SBGUICheckableComboBox#
ClassList > SBGUICheckableComboBox
The SBGUICheckableComboBox class extends QComboBox to support items with checkboxes.More...
#include <SBGUICheckableComboBox.hpp>
Inherits the following classes: QComboBox
Public Types#
| Type | Name |
|---|---|
| enum | DataRole Enumerates custom data roles for storing item data. |
Public Functions#
| Type | Name |
|---|---|
| SBGUICheckableComboBox (QWidget * parent=nullptr) Constructor for the checkable combo box. |
|
| void | addCheckableItem (const QString & text, int value, int role=DataRole::NaturalInt, bool checked=false) Adds a checkable item to the combo box with an integer value and a specified role. |
| void | addCheckableItem (const QString & text, bool checked=false) Adds a checkable item to the combo box with no associated integer value. |
| QMap< QString, bool > | getCheckState () const Retrieves the check state of all items in the combo box. |
| int | getSum (int role=DataRole::DoublingInt) const Computes the sum of values for checked items, based on a specified role. |
| void | setData (int combinedData, int role=DataRole::NaturalInt) Sets the integer data for all items in the combo box. |
| void | setEmptyMessage (const QString & emptySelectionMessage=COMBOBOX_EMPTY_MESSAGE) Sets the message to display when no items are selected. |
Protected Functions#
| Type | Name |
|---|---|
| void | hidePopup () override Overridden from QComboBox to update the display after the popup is hidden. |
| void | showPopup () override Overridden from QComboBox to customize the popup display. |
Detailed Description#
This class provides a combo box where each item can be checked or unchecked. It supports additional data roles for storing integer values that can be used for custom logic, such as summing checked values.
Short name: SBCheckableComboBox
Example:
#include "SBGUICheckableComboBox.h"
SBGUICheckableComboBox *combo = new SBGUICheckableComboBox(this);
combo->addCheckableItem("Item 1", 100, SBGUICheckableComboBox::NaturalInt, true);
combo->addCheckableItem("Item 2", 200);
combo->setEmptyMessage("Select at least one item");
Public Types Documentation#
enum DataRole#
Enumerates custom data roles for storing item data.
enum SBGUICheckableComboBox::DataRole {
NaturalInt = Qt::UserRole + 10,
DoublingInt = Qt::UserRole + 11
};
Public Functions Documentation#
function SBGUICheckableComboBox#
Constructor for the checkable combo box.
Constructs a checkable combo box with the given parent widget.
Parameters:
parentThe parent widget of this combo box, defaults to nullptr.
function addCheckableItem [1/2]#
Adds a checkable item to the combo box with an integer value and a specified role.
void SBGUICheckableComboBox::addCheckableItem (
const QString & text,
int value,
int role=DataRole::NaturalInt,
bool checked=false
)
Adds a checkable item with an integer value and role.
Parameters:
textDisplay text of the item.valueInteger value associated with the item.roleData role under which the integer value is stored.checkedInitial checked state of the item.
function addCheckableItem [2/2]#
Adds a checkable item to the combo box with no associated integer value.
Adds a checkable item without an associated integer value.
Parameters:
textDisplay text of the item.checkedInitial checked state of the item.
function getCheckState#
Retrieves the check state of all items in the combo box.
Retrieves the check state of all items.
Returns:
A map from item text to its checked state.
function getSum#
Computes the sum of values for checked items, based on a specified role.
Computes the sum of values for checked items using the specified role.
Parameters:
roleData role to use for summing values.
Returns:
The sum of values of checked items.
function setData#
Sets the integer data for all items in the combo box.
Sets the check state of items based on combined integer data and role.
Parameters:
combinedDataThe integer data representing combined values.roleData role under which the integer is stored.
function setEmptyMessage#
Sets the message to display when no items are selected.
void SBGUICheckableComboBox::setEmptyMessage (
const QString & emptySelectionMessage=COMBOBOX_EMPTY_MESSAGE
)
Sets the message displayed when no items are selected.
Parameters:
emptySelectionMessageThe message to display for an empty selection.
Protected Functions Documentation#
function hidePopup#
Overridden from QComboBox to update the display after the popup is hidden.
Hides the popup and updates the display text after hiding.
function showPopup#
Overridden from QComboBox to customize the popup display.
Shows the popup and updates the display text before showing.