How to get the text of a Qcomplete in a Qcombobox

200 Views Asked by At

I have a combobox that I fill with a QList and now I have generated a search engine with the help of the QCompleter, so far everything is fine, but I have edited it to make it visually more attractive, and it worked correctly until I have trouble selecting with the mouse one of the options that the QCompleter threw at me and the selection does not respect me, it only respects me if I give an Enter with the keyboard, but only for a moment.

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
   ui->setupUi(this);
   qApp->setStyleSheet("QAbstractItemView#completerPopup {font: 15pt ;color: rgb(255, 255, 255);}");
}


QCompleter *completer = new QCompleter(list, this);
completer->setFilterMode(Qt::MatchContains);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completer->popup()->setObjectName("completerPopup");
ui->cobobox->setCompleter(completer);

I manage to make it work but I have to remove some lines of code that are the ones that help me edit the QCompleter as Pupop.

QCompleter *completer = new QCompleter(list, this);
completer->setFilterMode(Qt::MatchContains);
completer->setCaseSensitivity(Qt::CaseInsensitive);
ui->cobobox->setCompleter(completer);

The error it throws when I select is the following Setting a QCompleter on non-editable QComboBox is not allowed.

1

There are 1 best solutions below

0
Ali Askari On

In the qtcreator form designer select your combobox and in properties window mark editable checkbox.