-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
So i noted that aUserData in addItem() is not used, but it would be very useful because in normal combobox i can retrieve the currentData() in item row. so i came up with the implement:
/* header
add QMap to map each checkbox to its value
*/
#include <QCheckBox>
private:
QMap<QCheckBox*, QVariant> values;
QList<QVariant> selectedValues;
// also add return value function
public:
QList<QVariant> currentValues();/* source
in setState() check and append selected value
*/
void MultiSelectComboBox::addItem(const QString& aText, const QVariant& aUserData)
{
//Q_UNUSED(aUserData);
/*
existing code
*/
values[checkBox] = aUserData; // map checkbox to value
}
void MultiSelectComboBox::stateChanged(int aState)
{
/*
existing code
*/
selectedValues.clear(); // clear
for (int i = 1; i < count; ++i){
/*
existing code
*/
if (checkBox->isChecked(){
// existing code
selectedValues.append(values[checkBox]); // get selected value
}
}
/*
existing code
*/
}
QList<QVariant> MultiSelectComboBox::currentValues(){
return selectedValues;
}i think it's more convenient this way
Metadata
Metadata
Assignees
Labels
No labels