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:

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

Constructs a checkable combo box with the given parent widget.

Parameters:

  • parent The 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:

  • text Display text of the item.
  • value Integer value associated with the item.
  • role Data role under which the integer value is stored.
  • checked Initial checked state of the item.

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
) 

Adds a checkable item without an associated integer value.

Parameters:

  • text Display text of the item.
  • checked Initial checked state of the item.

function getCheckState#

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

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

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.

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

Computes the sum of values for checked items using the specified role.

Parameters:

  • role Data 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.

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

Sets the check state of items based on combined integer data and role.

Parameters:

  • combinedData The integer data representing combined values.
  • role 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
) 

Sets the message displayed when no items are selected.

Parameters:

  • emptySelectionMessage The message to display for an empty selection.

Protected Functions Documentation#

function hidePopup#

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

void SBGUICheckableComboBox::hidePopup () override

Hides the popup and updates the display text after hiding.


function showPopup#

Overridden from QComboBox to customize the popup display.

void SBGUICheckableComboBox::showPopup () override

Shows the popup and updates the display text before showing.