Results 1 to 3 of 3

Thread: QListView

  1. #1
    Join Date
    Jan 2010
    Posts
    37
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QListView

    Hi!!

    While creating a simple file browser, i wrote the following code in the constructor of the class DirectoryView->

    QFileSystemModel *model=new QFileSystemModel;
    QListView *ListView=new QListView(this);
    ListView->setGeometry(0,59,240,260);
    model->setRootPath(QDir::rootPath());

    ListView->setModel(model);
    ListView->setRootIndex(model->index(QDir::rootPath()));
    ListView->show();

    ui->lineEdit->setText(QDir::rootPath());//to display the current path

    Now if i want the ListView to show the items inside the folder item which is clicked....what should i do??

    How can i get the path or QModelIndex of the item i click at runtime??
    Plz guide..

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListView

    See the signals QAbstractItemView::activated(), QAbstractItemView::clicked() ... and connect one of them to a custom slot, where you change the models root path according to the chosen folder.

    EIDT: And use LAYOUTS! Do not use manual positioning for your widgets.

  3. #3
    Join Date
    Jan 2010
    Posts
    37
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QListView

    But anyhow, i have to read the folder name when i click on any of the folder. For example in root directory, i have some folder, say "new folder". And my rootPath is "/root". And when i click on " new folder" my new rootPath must be "/root/new folder/. How it can be achieved by runtime random response of user? Plz guide a bit deep as i am unable to understand how to read the folder's name when user clicks on it. There's no method/property i've found to read the item's name. If listViewItem class is to be used then do i have to inherit the itemView class??.....
    I tried the following code->
    {
    ...
    ...
    ...
    connect(listView,SIGNAL(clicked(QModelIndex)),this ,SLOT(setPath(QModelIndex)));
    ...
    ...
    ...
    }

    void DirectoryView::setPath(QModelIndex index)
    {
    QString basePath=QDir::rootPath();
    QString currentPath=basePath+"\"+model->filePath(index);

    listView->setRootPath(currentPath);
    ...
    ...
    ...
    }

    This code compiles fine but gives some runtime error when i click on any folder item!!!!
    Please give me a deep guidance!!!!
    Last edited by Yayati.Ekbote; 1st March 2010 at 11:51.

Similar Threads

  1. QListView
    By Yayati.Ekbote in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2010, 18:50
  2. QListView and QDirModel
    By BTe in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2008, 16:36
  3. QListView
    By moowy in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2006, 14:14
  4. [QT3] QListView
    By incapacitant in forum Qt Programming
    Replies: 5
    Last Post: 29th January 2006, 14:31
  5. QListView
    By dragon in forum Newbie
    Replies: 1
    Last Post: 25th January 2006, 21:08

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.