Results 1 to 8 of 8

Thread: Collapse qtreewidgetitems that are childless

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2019
    Posts
    23
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Collapse qtreewidgetitems that are childless

    I have a QTreeWidget that basically displays files. Each segment of the path is a child of the previous path segment, ending with the file path filename, which is childless.I want to collapse this tree to show only the directories. I can do this by traversing the tree and setHidden for all the childless items. The problem is any directory segments that have no directory segments below them don't display the child Indicator, even if I setChildIndicatorPolicy to QTreeWidgetItem::ShowIndicator. I can't use collapseAll because it collapses everything down to the root directory of the drive.

    If this isn't enough information, I can post screen shots and code snippets.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Collapse qtreewidgetitems that are childless

    I can do this by traversing the tree and setHidden for all the childless items.
    So if you do this for file-only directories (eg. those with no subdirectories) then in effect you are telling the tree widget that rowCount() for these nodes is zero, and in that case the tree widget is doing what it is supposed to do: show an indication to the user that this is a leaf node that can't be expanded further because it contains no visible items.

    You can't have it both ways - you can't tell the tree widget that an item -doesn't- have children while at the same time have it display the expand indicator that says it -does- have children. If the tree did display this indicator, what is supposed to happen when the user clicks on it? And how is the user supposed to tell the difference between an unexpanded node that -does- have children and one that -doesn't- if they both have an expand indicator? You've introduced a conflicting and confusing behavior, with no way for the user to tell if there is something wrong when clicking doesn't do anything.

    I'd suggest that instead of introducing confusing and inconsistent behavior, you devise a set of icons you can use to give the user a cue about what is inside a node - something like a file folder icon for directories that contain only other directories, a file folder with pages of paper showing for directories that contain both directories and files, and just a set of pages of paper for directories that contain only files. Once a user learns the icons, then it is obvious which nodes can be expanded and which can't.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Dec 2019
    Posts
    23
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Collapse qtreewidgetitems that are childless

    Quote Originally Posted by d_stranz View Post
    So if you do this for file-only directories (eg. those with no subdirectories) then in effect you are telling the tree widget that rowCount() for these nodes is zero, and in that case the tree widget is doing what it is supposed to do: show an indication to the user that this is a leaf node that can't be expanded further because it contains no visible items.

    You can't have it both ways - you can't tell the tree widget that an item -doesn't- have children while at the same time have it display the expand indicator that says it -does- have children. If the tree did display this indicator, what is supposed to happen when the user clicks on it? And how is the user supposed to tell the difference between an unexpanded node that -does- have children and one that -doesn't- if they both have an expand indicator? You've introduced a conflicting and confusing behavior, with no way for the user to tell if there is something wrong when clicking doesn't do anything.

    I'd suggest that instead of introducing confusing and inconsistent behavior, you devise a set of icons you can use to give the user a cue about what is inside a node - something like a file folder icon for directories that contain only other directories, a file folder with pages of paper showing for directories that contain both directories and files, and just a set of pages of paper for directories that contain only files. Once a user learns the icons, then it is obvious which nodes can be expanded and which can't.
    Thanks much for your prompt response. Although i agree with your analysis confusing the user is not an issue as i have a column for each directory that says how many files are in it, please see attached screen shot.
    Attached Images Attached Images

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Collapse qtreewidgetitems that are childless

    i have a column for each directory that says how many files are in it
    But this is incomplete feedback from a user perspective. If you want the behavior of the tree to match the user's expectations, then you also need to provide a column that displays the number of directories within that node too. If the user sees that there are 4 files and zero directories, then if they have set a flag that says "show directories only", then they will not have the expectation of being able to expand that node.

    If you show only a file count -and- show the expand indicator for file-only nodes, then you have set up a conflict that the user can't resolve unless they turn off directory only mode and go look in that node again. From a user experience point of view, it is not happy feedback to say "if you click on a node and nothing happens, that means it's a file-only directory and not an indication that something isn't working correctly or your file system is corrupt". Or maybe not. But how can they tell?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Displaying a list of QTreeWidgetItems
    By GrahamB in forum Qt Programming
    Replies: 0
    Last Post: 17th January 2014, 09:48
  2. Replies: 1
    Last Post: 22nd April 2013, 14:57
  3. Replies: 1
    Last Post: 24th March 2011, 11:31
  4. Editing QTreeWidgetItems (PyQt4)
    By smhall316 in forum Newbie
    Replies: 1
    Last Post: 27th July 2010, 07:14
  5. Creating gaps between QTreeWidgetItems
    By ChiliPalmer in forum Qt Programming
    Replies: 4
    Last Post: 27th September 2009, 18:03

Tags for this Thread

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.