[Interest] Modify QCompleter's appearance

Sensei senseiwa at gmail.com
Wed Jul 10 14:29:33 CEST 2013


I can reply to my own question.

First of all, I created a new QListWidget and connected it to the 
QCompleter, setting a layout and padding:


     list_ = new QListWidget(this);
     layout_ = new QVBoxLayout(list_);
     list_->setLayout(layout_);
     list_->setStyleSheet("QListWidget { padding: 15px 5px 5px 5px; 
border: 1px solid lightgray; }");

Next, make sure the completer works and knows about the widget:

     // Start the completer
     completer_ = new QCompleter();
     model_     = new QStringListModel();
     model_->setStringList(keywords_);
     completer_->setPopup(list_);
     completer_->setModel(model_);
     completer_->setWidget(this);
     completer_->setCaseSensitivity(Qt::CaseSensitive);

Ok. We're cool. Now in the keyPressEvent function you can set the mask 
for your custom appearance when showing the popup:


     // Show it!
     completer_->complete(cr);
     list_->resize(width_, height_);
     list_->setMask(mask);
     list_->hide();
     list_->show();


You can see that I hide and show the widget because I think I've hit a bug.

If you set a mask, and even when calling repaint(), the *widget frame* 
is visible, in other words, you see your correctly masked widget along 
with the original rectangular frame.

Hiding and reshowing it makes this visual annoyance go away. Repainting 
has not effect.



More information about the Interest mailing list