Setting a QStyledItemDelegate on a QComboBox with a QCompleter?
-
I typed this question up, then I found the answer. So I thought I would submit it anyway.
I have a QComboBox with a QCompleter:
CompleterComboBox::CompleterComboBox( QWidget* parent ) : QComboBox( parent ) { setEditable( true ); setInsertPolicy( QComboBox::NoInsert ); QCompleter* completer = new QCompleter( this ); completer->setCaseSensitivity( Qt::CaseInsensitive ); completer->setFilterMode( Qt::MatchContains ); completer->setCompletionMode( QCompleter::PopupCompletion ); completer->setModel( model() ); setCompleter( completer ); lineEdit()->setPlaceholderText( "Type column name" ); setItemDelegate( new MyStyledItemDelegate ( this ) ); }The paint() method on the QStyledItemDelegate never gets called.
Turns out the last line should be:
completer->popup()->setItemDelegate( new MyStyledItemDelegate ( this ) );Hope that helps someone. My future self perhaps. ;0)
-
A AndyBrice has marked this topic as solved on