Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Setting a QStyledItemDelegate on a QComboBox with a QCompleter?
Forum Updated to NodeBB v4.3 + New Features

Setting a QStyledItemDelegate on a QComboBox with a QCompleter?

Scheduled Pinned Locked Moved Solved General and Desktop
1 Posts 1 Posters 180 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AndyBriceA Offline
    AndyBriceA Offline
    AndyBrice
    wrote on last edited by
    #1

    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)

    1 Reply Last reply
    2
    • AndyBriceA AndyBrice has marked this topic as solved on

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved