The only way I found is to set the size policy :
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
To copy to clipboard, switch view to plain text mode
And use this sizeHint :
QSize CPropertyEditorWidget
::sizeHint() const {
// Iterator of all items.
// Height of all item and header.
int Height = m_TreeWidget->header()->height() + 2;
// While iterator is valid.
while( *AllIterator )
{
// Update the height.
Height += m_TreeWidget->visualItemRect( Item ).height();
// Next iterator.
++AllIterator;
}
// Return the size hint.
return QSize( m_TreeWidget
->sizeHint
().
width(), Height
);
}
QSize CPropertyEditorWidget::sizeHint() const
{
// Iterator of all items.
QTreeWidgetItemIterator AllIterator( m_TreeWidget, QTreeWidgetItemIterator::All );
// Height of all item and header.
int Height = m_TreeWidget->header()->height() + 2;
// While iterator is valid.
while( *AllIterator )
{
// Update the height.
QTreeWidgetItem* Item = *AllIterator;
Height += m_TreeWidget->visualItemRect( Item ).height();
// Next iterator.
++AllIterator;
}
// Return the size hint.
return QSize( m_TreeWidget->sizeHint().width(), Height );
}
To copy to clipboard, switch view to plain text mode
There is a way to avoid the "+ 2" in this line ?
int Height = m_TreeWidget->header()->height() + 2;
int Height = m_TreeWidget->header()->height() + 2;
To copy to clipboard, switch view to plain text mode
Thanks for the help
EDIT:
The code before is not perfect on all situation, I have changed using "setFixedHeight( Height );" when one item is added but if the widget use the size policy Expanding when one item is added the siz policy change to fixed on height because of "setFixedHeight( Height );", that looks like a not easy problem to solve.
Bookmarks