Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
4.5.2
-
None
Description
QCompleter fails to work properly when using popup
completion and using either ::setCompletionColumn() or
::setCompletionRole().
This task is for comp2 in the following example
#include <QtGui>
#include <QStandardItemModel>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
// setup model
QStandardItemModel m;
QStandardItem *item1 = new QStandardItem("fooA");
item1->setData(QVariant("fooW"));
QStandardItem *item2 = new QStandardItem("foo1");
m.appendRow(QList<QStandardItem*>()<<item1<<item2);
item1 = new QStandardItem("fooB");
item1->setData(QVariant("fooX"));
item2 = new QStandardItem("foo2");
m.appendRow(QList<QStandardItem*>()<<item1<<item2);
item1 = new QStandardItem("fooC");
item1->setData(QVariant("fooY"));
item2 = new QStandardItem("foo3");
m.appendRow(QList<QStandardItem*>()<<item1<<item2);
item1 = new QStandardItem("fooD");
item1->setData(QVariant("fooZ"));
item2 = new QStandardItem("foo4");
m.appendRow(QList<QStandardItem*>()<<item1<<item2);
// setup gui
QWidget w;
QVBoxLayout *vlay = new QVBoxLayout(&w);
QLabel *l = new QLabel("In each edit box type the letter 'f' to cause the completion drop-down to appear. Then use the down-arrow to cycle through each item in the completion list. Note the behavior on each.\n\nThe first is correct. The second one does not allow you to scroll to any items except the first and the last (by using the up arrow key). The third one displays the wrong text in the drop-down, but fills the correct value into the edit box.\n\nSee comments in the code to see the exact line of code that causes each problem.");
l->setWordWrap(true);
vlay->addWidget(l);
QLineEdit *le1 = new QLineEdit();
vlay->addWidget(le1);
QLineEdit *le2 = new QLineEdit();
vlay->addWidget(le2);
QLineEdit *le3 = new QLineEdit();
vlay->addWidget(le3);
// setup completers
QCompleter *comp1 = new QCompleter(le1);
comp1->setModel(&m);
comp1->setCompletionColumn(0);
le1->setCompleter(comp1);
QCompleter *comp2 = new QCompleter(le2);
comp2->setModel(&m);
comp2->setCompletionColumn(1); ///// This line causes the problem. Can't use any column but 0
le2->setCompleter(comp2);
// QCompleter *comp3 = new QCompleter(le3);
comp3->setModel(&m);
comp3->setCompletionColumn(0);
comp3->setCompletionRole(Qt::UserRole+1); ///// This line causes the problem. Can't use any role but the default
le3->setCompleter(comp3);
// show widget
w.show();
return a.exec();
}