Results 1 to 2 of 2

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

  1. #1

    Default How to set the QComboBox's default index when it working under the model/view ?

    here is my codes:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv)
    4. {
    5. QApplication app(argc,argv);
    6. QDirModel* model = new QDirModel();
    7. QTreeView* view = new QTreeView();
    8. view->setModel(model);
    9. QComboBox* combo = new QComboBox();
    10. combo->setView(view);
    11. combo->setModel(model);
    12. combo->show();
    13. QString root = "D:/";/*QDir::rootPath();*/
    14. combo->setRootModelIndex((static_cast<QDirModel*>(combo->model()))->index(root));
    15. app.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by jpn; 13th June 2008 at 18:55. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to set the QComboBox's default index when it working under the model/view ?

    Qt Code:
    1. combo->setCurrentIndex(model->index(root).row());
    To copy to clipboard, switch view to plain text mode 
    ...although it works only for top level items. QComboBox doesn't support QTreeView very well. Search the forums, this subject has been discussed before.
    J-P Nurmi

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.