Results 1 to 16 of 16

Thread: file and diretory view

  1. #1
    Join Date
    Mar 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question file and diretory view

    hi
    I would like create a files and diretoris view whith 5 columns.
    how can i use QTreeWidget or QListWidget to do that ?
    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: file and diretory view

    Try using QDirModel and QTableView.

  3. #3
    Join Date
    Mar 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: file and diretory view

    thanks
    can i use QTreeWidget and QDirModel ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: file and diretory view

    No, you can't. What do you need QTreeWidget for? You can use QTreeView instead of the table view if you want.

  5. #5
    Join Date
    Mar 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: file and diretory view

    i will use it in a ftp client, to view a local and server files ...
    so i need a name, path and many informations of treewidget items to use with Qftp class

    thanks

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: file and diretory view

    Use QTreeView with QDirModel as suggested.

  7. #7
    Join Date
    Mar 2008
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: file and diretory view

    If i use for exampl a mouse event, how can i identify which item on the treeview is clicked ?
    for exampl on QTreeWidget i can use my class
    Qt Code:
    1. class myTreeWidget:public QTreeWidget
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void mousePressEvent (QMouseEvent *event)
    2. signals:
    3. void itemClicked (QTreeWidgetItem *);
    4. //......
    5. void myTreeWidget::itemClicked(QMouseEvent * e)
    6. {
    7. QTreeWidgetItem *selectedItem = itemAt(e->pos());
    8. emit itemClicked(selectedItem);
    9. }
    To copy to clipboard, switch view to plain text mode 
    how can i use like this on QTreeView
    thank you

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: file and diretory view


  9. #9
    Join Date
    Feb 2008
    Posts
    60
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: file and diretory view

    Dear all,

    I am using QTableView with QDirModel to display the local file system.

    I have set the filter with "QDir::AllEntries". it is displaying all folders and Files including "." and ".." items.

    If I use QDir::NoDotAndDotDot, both "." and ".." is filtered.

    I need only ".." but not "."

    can anyone suggest me the way of doing this.

    Thanks in advance.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: file and diretory view

    Apply a sort filter proxy model that will filter out the single dot.

  11. The following user says thank you to wysota for this useful post:

    jay (28th August 2008)

  12. #11
    Join Date
    Feb 2008
    Posts
    60
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: file and diretory view

    Dear all,

    I have used QSortFilterProxyModel as per wysota's suggestion. its working fine. thanks for this.
    can anyone help me with regular expression that should display only ".." not "."

    proxyModel->setFilterRegExp ( QRegExp ( "......." ) );
    proxyModel->setFilterKeyColumn ( 0 );

    thanks in advance.

  13. #12
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: file and diretory view

    Am not sure but
    "[^\.]"
    ie. Anything except '.'
    Also have a look at QRegExp

  14. #13
    Join Date
    Jun 2008
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: file and diretory view

    thanks for your reply.

    I have checked with this, but it filters both ".." and "."

    my requirement is only ".."

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: file and diretory view

    You can subclass the proxy and reimplement its filterAcceptsRow() method.

  16. #15
    Join Date
    Oct 2008
    Location
    Taiwan
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: file and diretory view

    It seems like an old article....
    But I have the same question about how to show files and directory of ftp.....
    I choose QTreeView and QDirModel.....
    What should I specify the parameters when I call QTreeView::setRootIndex() ??
    Thanks.

  17. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: file and diretory view

    QDirModel can't be used with FTP.

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.