Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Need to have QDockView resize automatically when QTreeView child node expanded
Forum Update on Monday, May 27th 2025

Need to have QDockView resize automatically when QTreeView child node expanded

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 452 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dboyallstars
    wrote on last edited by
    #1

    I have a QTreeView inside of a QDockView. I want the columns/headers to resize based on contents (ideally never show ellipses, require resizing, or REQUIRE a horizontal scroll bar [although it's acceptable to have a horizontal scrollbar if the user chooses to shrink the width of the QDockView]). Essentially, when a tree element is expanded, the DockView's width should expand to accommodate the contents of both columns without requiring a scrollbar, and both columns' data should be visible by default.

    This is what I currently have:

    	connect (
    		dataTreeClass.dataTree,
        		&QTreeView::expanded,
    		this,
    		&myClass::handleTreeExpansion
            );
    
    void myClass::handleTreeExpansion (QModelIndex const &index_)
    {
    	dataTreeClass.dataTree->resizeColumnToContents(0);
    	dataTreeClass.dataTree->resizeColumnToContents(1);
    }
    

    I've tried all options for QHeaderView scrollbar behaviors and gotten no luck. So much of the data gets hidden with resizing (even based on hints), and it is especially bad when the tree expands such that the vertical scrollbar becomes visible, at which point the data in the second column becomes very hidden.

    My logic was to set the width of the QDockView to the sum of the width of the QTreeView plus the width of vertical scrollbar, after resizeColumnsToContents with each signal, but the closest I've gotten is that the size of the QDockView just continuously grows larger and larger with each tree node expansion (incidentally by 30 pixels each time, which is also the width of the vertical scroll bar; so I'm sure it's a logic error, but I've been working on this seemingly simple problem for far too long).

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What version of Qt are you using ?
      On what platform ?
      Can you provide a minimal compilable example that shows the state where you are currently ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        What version of Qt are you using ?
        On what platform ?
        Can you provide a minimal compilable example that shows the state where you are currently ?

        D Offline
        D Offline
        dboyallstars
        wrote on last edited by dboyallstars
        #3

        @SGaist Hey thank you. I'm using Qt 5.9.2 on CentOS Linux. I'm reasonably sure I'm unable to provide anything compilable, as I'm working on proprietary code, and I have to submit minimal code snippets here to maintain non-disclosure compliance.

        The code given on https://forum.qt.io/topic/69181/qtreeview-last-column-always-visible-without-scrollbars/2 seemed very close to what I wanted to do, with the exception of that OP wanting to always view the second column, whereas I want to always view both columns.

        Essentially, I have a dock on the right side of the window with a QTreeView and as the tree is expanded, I want the QDockView to expand to the left, eliminating the need (but not the option) for a horizontal scroll bar. The left-expansion of the QDockView must consider both the width of the QTreeView and the vertical scroll bar, should it be necessary that it appear.

        I appreciate your response. Thank you.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I understand and no need for your application code.

          I was thinking of a minimal QTreeView (maybe QTreeWidget ?) with random data in it that reproduce the situation you have with your application.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved