PDA

View Full Version : QComboBox MaxVisibleItems overflow



minsoub
24th February 2010, 01:41
I tried setting MaxVisibleItems of QComboBox.

I tried coding something like :


QComboBox *combo = new QComboBox;
combo->setModel(queryModel);
combo->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);

// MaxVisibleItems set
QCompleter *p = new QCompleter(queryModel);
p->setMaxVisibleItems(20);
combo->setCompleter(p);
combo->show();


The code execute, then QComboBox Size is overflowed and it's height exceed screen size.
QComboBox item count is 300.

Why don't display so MaxVisibleItem as I'm setting?

What's incorret?

please, Somebody help me.

ecanela
24th February 2010, 02:37
the example no reproduce the problem. i create a model for use whit the example and i dont see any problem.


please post a more complete example. if queryModel is a SQL model class. try to create a dummy DB to reproduce the problem
a dummy DB is a sqlite DB whit one table, whit the data to cause the problem.



// my model
int numItems = 300;
QStandardItemModel * queryModel = new QStandardItemModel(numItems , 1);
for (int row = 0; row < numItems ; ++row) {
QStandardItem *item = new QStandardItem(QString("row %0").arg(row));
queryModel->setItem(row, 0, item);

}

// not my code.
QComboBox *combo = new QComboBox;
combo->setModel(queryModel);
combo->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);

// MaxVisibleItems set
QCompleter *p = new QCompleter(queryModel);
p->setMaxVisibleItems(20);
combo->setCompleter(p);
combo->show();

minsoub
24th February 2010, 09:03
First of all, thanks to your answer.

Sorry, I told not about My Test OS.
My Test Os is Linux.

My code and Your code tested in My Linux machine, QComboBox's height exceed Screen size.

I don't know why it is occurred.

following attached file.

================================================== ==================================


the example no reproduce the problem. i create a model for use whit the example and i dont see any problem.


please post a more complete example. if queryModel is a SQL model class. try to create a dummy DB to reproduce the problem
a dummy DB is a sqlite DB whit one table, whit the data to cause the problem.



// my model
int numItems = 300;
QStandardItemModel * queryModel = new QStandardItemModel(numItems , 1);
for (int row = 0; row < numItems ; ++row) {
QStandardItem *item = new QStandardItem(QString("row %0").arg(row));
queryModel->setItem(row, 0, item);

}

// not my code.
QComboBox *combo = new QComboBox;
combo->setModel(queryModel);
combo->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);

// MaxVisibleItems set
QCompleter *p = new QCompleter(queryModel);
p->setMaxVisibleItems(20);
combo->setCompleter(p);
combo->show();

ecanela
27th February 2010, 01:19
problably you need upgrade the version of Qt.

another option is try to simplify your code. and isolate the problem. maybe is a bug.