QComboBox doing weird things on first show
-
I created a little dialog window with a QComboBox reading its entries from a database. What's so weird about it, is that the entries are moving to the top of the window when the combobox is opened for the first time...
That's my dialog
!http://dl.dropbox.com/u/8619833/dialog.jpg(Dialog)!When clicking the combobox for the first time, it first seems like it would open correctly
!http://dl.dropbox.com/u/8619833/dialog2.jpg(Dialog2)!But then the entries suddenly move to the top
!http://dl.dropbox.com/u/8619833/dialog3.jpg(Dialog3)!After that, the combobox is working fine. No problems, until I close the dialog and open it up again...
-
I know there is some logic inside QComboBox to ensure, it is visible. Looks like there is a bug in.
I tried it in a simple project on WinXP where it worked well.
SO perhaps it's a win 7 problem or a style problem.
Could you try to run the app with a non win7 style or with windows Aero switched off? -
so, disabling Aero did not work but on WinXP it worked?
What you could also try is to start with a specific style:in your main function use QWindowsStyle explictitly, perhaps it's a windows 7 style issue
and then, after evaluating this, I would write a bug report on "JIRA":http://bugreports.qt.nokia.com/secure/Dashboard.jspa -
I have a simple test on Win7 and it works fine. I have added 100 items to combo box.
!http://imageshack.us/photo/my-images/716/combobox.jpg/(combo box)! -
[quote author="cincirin" date="1309853968"]I have a simple test on Win7 and it works fine. I have added 100 items to combo box.
!https://dl-web.dropbox.com/get/comboBox.jpg?w=0c4c0b8a(comboBox)![/quote]I changed Win7-Style to Windows7-Basic and I did not work...
-
Please "file a bug report":http://bugreports.qt.nokia.com/, especially if you have some small application demonstrating the issue.
-
[quote author="cincirin" date="1309854965"][quote author="EukeSnud" date="1309854079"]I changed Win7-Style to Windows7-Basic and I did not work...[/quote]
Interestingly enough, I also changed Windows 7 Aero themes to Windows 7 Basic, and all works perfectly.
[/quote]But you did have problems with Windows 7 aero theme?
-
Might it be a problem with my QDialog? Let me post a small project containing a slim version of it...
qdbdialog.h
@#ifndef QDBDIALOG_H
#define QDBDIALOG_H#include <QDialog>
#include <QString>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QCheckBox>
#include <QtGui/QComboBox>
#include <QtGui/QDialogButtonBox>class QDbDialog : public QDialog
{
Q_OBJECT
public:
QDbDialog(QWidget * parent = 0, Qt::WindowFlags f = 0);
QDbDialog(QString *usr, QString *pwd, QString *dsn);
~QDbDialog();public slots:
void closeWithOk();
void closeWithCancel();
void closeWithB(bool b);private:
QString *user;
QString *passwd;
QString *dstn;QLabel *lblUsr; QLabel *lblPwd; QLabel *lblDsn; QLineEdit *txtUsr; QLineEdit *txtPwd; QComboBox *cbDsn; QDialogButtonBox *btnBox;
};
#endif@qdbdialog.cpp
@#include "qdbdialog.h"
#include <QLayout>QDbDialog::QDbDialog(QWidget * parent, Qt::WindowFlags f) :
QDialog(parent,f),user(new QString("user")),passwd(new QString("pwd")),dstn(new QString("dsn")) {
}QDbDialog::QDbDialog(QString *usr, QString *pwd, QString *dsn) : user(usr),passwd(pwd),dstn(dsn) {
lblUsr = new QLabel("&Username:");
txtUsr = new QLineEdit;
lblUsr->setBuddy(txtUsr);lblPwd = new QLabel("&Password:"); txtPwd = new QLineEdit;
txtPwd->setEchoMode(QLineEdit::Password);
lblPwd->setBuddy(txtPwd);lblDsn = new QLabel("&ODBC-Datasource");
cbDsn = new QComboBox();
lblDsn->setBuddy(cbDsn);QStringList dsnlist;
for (int i=0;i<100;i++) {
dsnlist.push_back("TEST" + QString::number(i+1));
}dsnlist.sort();
cbDsn->addItems(dsnlist);btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(btnBox,SIGNAL(accepted()),this,SLOT(closeWithOk()));
connect(btnBox,SIGNAL(rejected()),this,SLOT(reject()));QGridLayout *mainLayout = new QGridLayout();
mainLayout->addWidget(lblUsr,0,0);
mainLayout->addWidget(txtUsr,0,1);
mainLayout->addWidget(lblPwd,1,0);
mainLayout->addWidget(txtPwd,1,1);
mainLayout->addWidget(lblDsn,2,0);
mainLayout->addWidget(cbDsn,2,1);
mainLayout->addWidget(btnBox,4,0,1,2);setLayout(mainLayout);
}QDbDialog::~QDbDialog() {
}
void QDbDialog::closeWithOk() {
*user = txtUsr->text();
*passwd = txtPwd->text();
*dstn = cbDsn->currentText();
done(QDialog::Accepted);
}void QDbDialog::closeWithCancel() {
done(QDialog::Rejected);
}void QDbDialog::closeWithB(bool b) {
if (b)
done(QDialog::Accepted);
else
done(QDialog::Rejected);
}@main.cpp
@#include "qdbdialog.h"
#include <QtGui/QApplication>int main(int argc, char *argv[])
{
QApplication a(argc, argv);QString usr;
QString pwd;
QString dsn;QDbDialog dbdiag(&usr,&pwd,&dsn);
dbdiag.exec();return a.exec();
}
@ -
-
[quote author="cincirin" date="1309861645"]I tested your posted code both with Win7 Aero theme and with Win7 Basic, but I could not replicate your problem.
[quote author="EukeSnud" date="1309849910"]But then the entries suddenly move to the top[/quote]
This happens without you doing anything?
[/quote]Yes, the entries are in the right spot for less than a second and then jump to the top. (As shown on the screens)
-
[quote author="EukeSnud" date="1309856718"]Just added a combobox to my main widget and filled it with 100 entries. No problems with this one ... [/quote]
From what I understand, it is part of the code you posted, and you have no problems.
Are you sure that when you fill other combo box with ODBC drivers, you don't call other functions ? -
The code I posted is of a dialog window which can be executed as shown in main.cpp and this code causes the combobox on my dialog to perform the strange steps described...
However the dialog is part of a greater project and because I didn't want to post all of its source files I created this slim project above just executing my custom dialog.What I meant was, that I added a combobox to the main widget in my greater project and filled it with 100 entries. This combobox does not show the strange behaviour like the one mentioned in the code above!