How to set the QComboBox's default index when it working under the model/view ?
here is my codes:
Code:
#include <QtGui>
int main(int argc, char **argv)
{
view->setModel(model);
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.
Re: How to set the QComboBox's default index when it working under the model/view ?
Code:
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.