Hi, I'm trying to implement a combo box that would allow more than one selection(for flag purpose). I want the combo box to display check boxes in it instead of plain strings.
I already got that part covered usung a delegate on the combo box's list view for painting.
Now I need to be able to check the check boxes from within the list view. I tried implementing createEditor in my item delegate but it doesn't get called.
One last question, I would like to display the combined flags in the combo box's edit like Flag1 | Flag2 | Flag4. Is it possible to do it instead of the last selected item ?
Here's my code for the delegate in case you're interested :
void AcuiMultiSelectionComboBoxItemDelegate::paint(
const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
buttonStyle.text = index.model()->data(index, Qt::DisplayRole).toString();
buttonStyle.rect = option.rect;
qApp->style()->drawControl(
&buttonStyle,
painter );
}
QWidget* AcuiMultiSelectionComboBoxItemDelegate
::createEditor( const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
index.model()->data(index, Qt::DisplayRole).toString(),
parent );
return checkBox;
}
void AcuiMultiSelectionComboBoxItemDelegate::paint(
QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
QStyleOptionButton buttonStyle;
buttonStyle.text = index.model()->data(index, Qt::DisplayRole).toString();
buttonStyle.rect = option.rect;
qApp->style()->drawControl(
QStyle::CE_CheckBox,
&buttonStyle,
painter );
}
QWidget* AcuiMultiSelectionComboBoxItemDelegate::createEditor(
QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
QCheckBox* checkBox = new QCheckBox(
index.model()->data(index, Qt::DisplayRole).toString(),
parent );
return checkBox;
}
To copy to clipboard, switch view to plain text mode
Feel free to give any comments, recommendation.
Bookmarks