简体   繁体   中英

How to get the text of a Qcomplete in a Qcombobox

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM