[Interest] Anyway to tell if a QModelIndex's data will be displayed with an elide?

Volker Hilsheimer volker.hilsheimer at qt.io
Fri Jun 3 14:12:23 CEST 2022



> On 2 Jun 2022, at 19:31, Scott Bloom <scott at towel42.com> wrote:
> 
> I have a request, to open a dialog without out any eliding, which is easy enough to do via the views textElideMode.
>  
> So I can resize all the columns to fit, pretty straight forward, if I don’t set the textElideMode
>  
> However, they also want no the data to be full visible, and not have to resize the dialog/scroll. 
>  
> However, I cant seem to find a proper “this is the size the treeview (though the same issue exists for any abstractview) minimum size hnt that wont require scrollbars.
>  
> Am I missing something obvious? (I must be)
> 
> Scott


There is no need for QTreeView to calculate a sizeHint for the entire tree, because, well, it is a scrollview :) And calculating a sizeHint would also mean that the view has to update layouts when data that influences the sizeHint changes, and that would be quite expensive (the view does have to do at least some of that anyway to adjust the scrollbars, but since scrolling is “per row” rather than “per pixel”, we can optimize that a lot; see QTreeViewPrivate::updateScrollBars()).

I think the best you can do is to get the visualRect of the last index, and then calculate the view’s sizeHint based on that. That means that the tree has to be fully expanded.


Volker



More information about the Interest mailing list