Horst Walter
Horst Walter

Reputation: 14081

QLineEdit`s QCompleter stylesheet

Having a QLineEdit with a plain vanilla QStringList QCompleter. I wonder if I can change the appearance of the dropdown (I want to have either a min. size or smaller scrollbar).

QCompleter

Clarification: I want to set it in a stylesheet, not in the code.

Summary of my findings so far:

  1. Pretty good summary here: https://forum.qt.io/topic/26703/solved-stylize-using-css-and-editable-qcombobox-s-completions-list-view/12
  2. I have to use QStyledItemDelegate and
  3. give the popup a name for the qss selector
  4. I have tried that and it does not work for me, but seems to work for others

Upvotes: 0

Views: 2829

Answers (1)

JefGli
JefGli

Reputation: 791

A simple straight forward solution is to set the stylesheet of the QScrollBar used by the popup of the QCompleter. My knowledge of qss is little, so I don't know if you can set a minimum size that way, but you can always have a look at verticalScrollBar().

Here is some code for the qss way:

#include <QAbstractItemView>
#include <QCompleter>
#include <QLineEdit>
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QLineEdit edit;
    edit.show();

    QStringList completionList;
    for (int a = 0 ; a < 10 ; ++a) {
        completionList << QString("test%1").arg(a);
    }

    QCompleter completer(completionList);

    edit.setCompleter(&completer);

    QAbstractItemView *popup = completer.popup();

    popup->setStyleSheet("QScrollBar{ width: 50px;}");

    return a.exec();
}

Upvotes: 4

Related Questions