Important: Please read the Qt Code of Conduct -

QTreeView resize rows

  • Hi everyone,

    I have a QTreeView, a model and a custom delegate with all the necessaries implemented. My problem is that the delegate's sizeHint method is only ever called once per item and that subsequent changes to the tree view's size does not propagate down to the individual items themselves.

    What this means is that row heights are set at widget start-up and do not adjust as they should when the user drags the splitter that the tree view resides in.

    Any ideas as to how I can get around this?


    EDIT: I neglected to mention that I expect the row heights to resize due to my delegate implementation. The delegate applies syntax highlighting and is also responsible for wrapping text to fit into the available width. This is where the issue arises since it does this successfully but ONLY at start-up (i.e. if the widget starts with width x, the individual items get wrapped and displayed correctly, but the row heights do not get adjusted upon subsequent width changes). I hope this makes more sense.

  • I am fairly new to Qt so I am not certain I understand your question. But I have used this type of widget in other API's. Don't the row heights depend on the font/icon size rather than the size of the widget? As far as I know, a tree view is scrollable so if the user drags a splitter horizontally, that would not resize individual rows at all. It would only change the size of the view itself (and whether or not a scroll bar is displayed).

    My guess is that if you want to resize the the individual rows on resize of the widget you will probably need to create/subclass your own widget...

    EDIT: You might also be able to accomplish this by creating your own style for the treeview widget and manually setting that style when the treeview widget gets instanced. Styles often handle sizing changes etc... The details of how to do this though are beyond my current experience with qt.

  • Thanks for the reply, but I just realise that I neglected to include information regarding WHEN I expect the rows to resize their heights. Original post edited.

Log in to reply