Results 1 to 3 of 3

Thread: QDirModel

  1. #1
    Join Date
    Nov 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDirModel

    Hi,

    I am trying to develop a program which uses the QComboBox and a QListBox coupled with QDirModel.

    The QCombobox will be listing all the drives and the listbox will be containing the contents of the Drive that I select from the QComboBox.

    I am not able to connect them together.

    Can someone please help me.

    Thanks

  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: QDirModel

    Start by extending QComboBox with a "currentIndexChanged" signal with QModelIndex parameter:
    Qt Code:
    1. class ComboBox : public QComboBox
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. ComboBox(QWidget* parent = 0) : QComboBox(parent)
    7. {
    8. connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(emitCurrentIndexChanged(int)));
    9. }
    10.  
    11. signals:
    12. void currentIndexChanged(const QModelIndex& index);
    13.  
    14. private slots:
    15. void emitCurrentIndexChanged(int index)
    16. {
    17. emit currentIndexChanged(rootModelIndex().child(index, modelColumn()));
    18. }
    19. };
    To copy to clipboard, switch view to plain text mode 
    Then you can just connect ComboBox::currentIndexChanged(QModelIndex) to QAbstractItemView::setRootIndex(QModelIndex) and you're done.
    Qt Code:
    1. int main(int argc, char* argv[])
    2. {
    3. QApplication a(argc, argv);
    4. QDirModel dirModel;
    5. ComboBox comboBox;
    6. comboBox.setModel(&dirModel);
    7. comboBox.show();
    8. QListView listView;
    9. listView.setModel(&dirModel);
    10. listView.show();
    11. a.connect(&comboBox, SIGNAL(currentIndexChanged(QModelIndex)), &listView, SLOT(setRootIndex(QModelIndex)));
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    rvb13 (2nd November 2007)

  4. #3
    Join Date
    Nov 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDirModel

    Awesome !
    Thanks !

Similar Threads

  1. QDirModel - show directory ".."?
    By jamd in forum Qt Programming
    Replies: 3
    Last Post: 23rd April 2009, 19:51
  2. QDirModel
    By L.Marvell in forum Newbie
    Replies: 2
    Last Post: 5th June 2007, 14:47
  3. Replies: 2
    Last Post: 12th April 2007, 11:11
  4. Replies: 1
    Last Post: 15th March 2007, 20:45
  5. QDirModel, Model/View, extend the file onfo
    By VlJE in forum Qt Programming
    Replies: 10
    Last Post: 11th December 2006, 10:56

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.