Web Analytics Made Easy - Statcounter
Skip to content

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 Usage:

#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.

explicit SBGUICheckableComboBox::SBGUICheckableComboBox (
    QWidget * parent=nullptr
) 

Parameters:

  • parent The parent widget of this combo box, defaults to nullptr if not specified.

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
) 

Parameters:

  • text The display text of the item.
  • value The integer value associated with the item.
  • role The role under which the integer value is stored, defaults to NaturalInt.
  • checked Initial checked state of the item, defaults to false.

function addCheckableItem [2/2]#

Adds a checkable item to the combo box with no associated integer value.

void SBGUICheckableComboBox::addCheckableItem (
    const QString & text,
    bool checked=false
) 

Parameters:

  • text The display text of the item.
  • checked Initial checked state of the item, defaults to false.

function getCheckState#

Retrieves the check state of all items in the combo box.

QMap< QString, bool > SBGUICheckableComboBox::getCheckState () const

Returns:

QMap where the key is the item text and the value is the checked state (true if checked).


function getSum#

Computes the sum of values for checked items, based on a specified role.

int SBGUICheckableComboBox::getSum (
    int role=DataRole::DoublingInt
) const

Parameters:

  • role The data role to use for summing values, defaults to DoublingInt.

Returns:

The sum of the values of checked items.


function setData#

Sets the integer data for all items in the combo box.

void SBGUICheckableComboBox::setData (
    int combinedData,
    int role=DataRole::NaturalInt
) 

Parameters:

  • combinedData The integer value to set for all items.
  • role The data 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
) 

Parameters:

  • emptySelectionMessage The message to display, defaults to predefined empty message constant.

Protected Functions Documentation#

function hidePopup#

Overridden from QComboBox to update the display after the popup is hidden.

void SBGUICheckableComboBox::hidePopup () override


function showPopup#

Overridden from QComboBox to customize the popup display.

void SBGUICheckableComboBox::showPopup () override