PDA

View Full Version : How to set the QComboBox's default index when it working under the model/view ?



walala123456
13th June 2008, 13:04
here is my codes:


#include <QtGui>

int main(int argc, char **argv)
{
QApplication app(argc,argv);
QDirModel* model = new QDirModel();
QTreeView* view = new QTreeView();
view->setModel(model);
QComboBox* combo = new QComboBox();
combo->setView(view);
combo->setModel(model);
combo->show();
QString root = "D:/";/*QDir::rootPath();*/
combo->setRootModelIndex((static_cast<QDirModel*>(combo->model()))->index(root));
app.exec();
}

the ComboBox always show the root as "C:",how can I set it to the "D:"?

I'm using Qt 4.4.0.If you use the old version such as 4.3.1,there will be a few other bugs.

thanks a lot.

jpn
13th June 2008, 18:58
combo->setCurrentIndex(model->index(root).row());
...although it works only for top level items. QComboBox doesn't support QTreeView very well. Search the forums, this subject has been discussed before.