Results 1 to 8 of 8

Thread: Collapse qtreewidgetitems that are childless

  1. #1
    Join Date
    Dec 2019
    Posts
    13
    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
    4,631
    Thanks
    256
    Thanked 735 Times in 725 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    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
    13
    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
    4,631
    Thanks
    256
    Thanked 735 Times in 725 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    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.

  5. #5
    Join Date
    Dec 2019
    Posts
    13
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Collapse qtreewidgetitems that are childless

    Thanks again for your attention. I don't see the conflict you mention. If you look at the screen shot I just uploaded you can see that the _videos directory has both a file and a directory. There is no abiguity as the subdirectory is shown below it (folder1). What I'm trying to show is the directory structure without the files and use the expand flags to show the files. It sounds like you are telling me that qt does not provide for this action. Which is ok, I can find another way to accomplish what I want.
    video1.jpg


    Added after 1 22 minutes:


    I found a solution to my problem, I created an empty column 0 that I then hide. I then process mouse clicks to collapse and expand the way I would like. This doesn't have a noticeable effect on performance, even with 10000 records. Thanks for taking the time to respond.
    Last edited by spike6479; 10th August 2020 at 22:04.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,631
    Thanks
    256
    Thanked 735 Times in 725 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Collapse qtreewidgetitems that are childless

    I don't see the conflict you mention. If you look at the screen shot I just uploaded you can see that the _videos directory has both a file and a directory.
    Your screen shot shows a fully-expanded, directories-only tree. Of course there is no ambiguity there - everything that can be expanded is. Now, collapse the whole thing. If -every- node shows an expand indicator -whether it can be expanded or not- how do I know which ones can and which ones can't? It doesn't matter that your GUI shows me how many files are in the folder that the node points to. If the tree shows the expand indicator, I expect that if I click on it it will show me the contents of the folder, but in your design that only works for some nodes and not others, and there is no explanation why.

    Look at it from another perspective. Say you bring up a web page in your browser. That page contains words or phrases that are underlined, highlighted in blue text, or some other convention that you -know- means these are hyperlinks and if you click on one it takes you to another page. However, on this page, all the link phrases look the same, but only half of them actually do anything. Are these links broken? Or is it a security setting in your browser that is preventing them from working? Or is there some other problem? You have no clue, because the GUI convention says it should work and it doesn't. That is exactly what you are telling the user by putting "broken" expand indicators on nodes that can't be expanded.

    But if you want angry confused users filing bug reports over the inconsistent behavior, that's up to you.
    <=== 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.

  7. #7
    Join Date
    Dec 2019
    Posts
    13
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Collapse qtreewidgetitems that are childless

    I'm not sure your analogy to a web page is applicable. If there is a file count, expanding the directory will always show more (i.e. the files in the directory). This is a video management system. When collapsed to directories only, you can see what shows and seasons are available, expanding any of the directories will show the episodes in that directory. I have implemented it now such that the Collapse/Expand All button shows just directories or directories and all files. Right clicking on a directory will hide or unhide the files, depending on the current state. I just don't see the ambiguity.
    videoExpanded.jpgvideoExpandedPart.jpg

    Thanks very much for your time and thoughts.

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,631
    Thanks
    256
    Thanked 735 Times in 725 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Collapse qtreewidgetitems that are childless

    Sorry, I feel like I am arguing with a wall. Do your interface as you see fit, and when your users complain about not being able to expand certain parts of the tree even though the indicator says they should be able to, then you can explain to them why that's not ambiguous behavior and see what they say about it.
    <=== 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, 08:48
  2. Replies: 1
    Last Post: 22nd April 2013, 13:57
  3. Replies: 1
    Last Post: 24th March 2011, 10:31
  4. Editing QTreeWidgetItems (PyQt4)
    By smhall316 in forum Newbie
    Replies: 1
    Last Post: 27th July 2010, 06:14
  5. Creating gaps between QTreeWidgetItems
    By ChiliPalmer in forum Qt Programming
    Replies: 4
    Last Post: 27th September 2009, 17: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.