I have dialog with 2 QTreeWidgets. One of them hidden.
The problem is - how adjust size of dialog to the minimum size. (Dialog appears with width which is enough for placing 2 QTreeWidgets)
I have dialog with 2 QTreeWidgets. One of them hidden.
The problem is - how adjust size of dialog to the minimum size. (Dialog appears with width which is enough for placing 2 QTreeWidgets)
This should work:
my_dialog::my_dialog (QWidget* p)
:QDialog(p)
{
setupUi(this);
treeWidget_2->hide();
setMinimumSize( sizeHint() );
}
Marcel
No this is not works properly, because it sets Minimum size to sizeHint() - correct will be sizeHint()/2
Have you tried it?
Since one of the tree widgets is hidden the sizeHint of the dialog will be exactly the width of the visible tree widget.
Marcel
Yes I have tried,
but I found solution
We need to reimplemet sizeHint()
my_dialog::my_dialog (QWidget* p)
:QDialog(p)
{
setupUi(this);
treeWidget_2->hide();
resize(sizeHint());
}
my_dialog::~my_dialog()
{
}
QSize my_dialog::sizeHint()
{
return QSize(treeWidget_2->geometry().width()+10,treeWidget_2->geometry().height()+50);
}
we can only call resize without reimplementing sizeHint - it works
But I want to extend the problem :
Instead of 2 QTreeWidgets I have 1 custom widget in which this 2 QTreeWidgets exist
one of them is hidden ... resize is not help in this case
Apply what you did for the dialog to the custom widget,
Set the minimum size of the custom widget to the size hint of the tree view that is visible.
Let me know if works.
Marcel
Bookmarks