+2 comes from the frame size. You should use QStyle::styleHint() to ask the style for the proper frame size of your style.
+2 comes from the frame size. You should use QStyle::styleHint() to ask the style for the proper frame size of your style.
I have found an easy way to handle my problem, I have a SetFixedHeightToShowAllItems() and I set the size policy to fixed when needed.
About the frame width I only found this one, all other are for specific widget but not the tree :
That return the value 1, I guess it's normal because there is one border on top and one on bottom so that's (2*FrameWidth).Qt Code:
To copy to clipboard, switch view to plain text mode
Is it the correct styleHint or that can cause problems ?
Hmm... actually I think I told you wrong. You should use pixelMetric() with PM_DefaultFrameWidth or alike.
ok Thanks, I have changed like that :
Qt Code:
void CPropertyEditorWidget::SetFixedHeightToShowAllProperties() { // Iterator of all items. // Initialize the SpinBox style option. // Height of all item and header. int Height = m_TreeWidget->header()->height() + (2 * FrameWidth); // While iterator is valid. while( *AllIterator ) { // Update the height. Height += m_TreeWidget->visualItemRect( Item ).height(); // Next iterator. ++AllIterator; } // Set the fixed height. setFixedHeight( Height ); }To copy to clipboard, switch view to plain text mode
Wouldn't it be easier to query for the visual rect of the last item only? You could then take its bottom() value.
I have tried :
But that doesn't work, I have the scrollbar on the right, using the iterator version the scrollbar is not visible.Qt Code:
void CPropertyEditorWidget::SetFixedHeightToShowAllProperties() { const int LastItemBottom = m_TreeWidget->visualItemRect( m_TreeWidget->topLevelItem( m_TreeWidget->topLevelItemCount() - 1 ) ).bottom(); setFixedHeight( m_TreeWidget->header()->height() + ( 2 * FrameWidth ) + LastItemBottom ); }To copy to clipboard, switch view to plain text mode
I have added the +1 on the "bottom()" version and that works good, thanks for the comment on bottom(), this version is faster surely.Note that for historical reasons this function returns top() + height() - 1; use y() + height() to retrieve the true y-coordinate.
Just keep in mind your code will not work for trees where items have children. You'd have to recursively descend to the deep-most visible child of the last item.
Bookmarks