PDA

View Full Version : Sizing problem



Levon Nikoghosyan
2nd April 2007, 17:36
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)

marcel
2nd April 2007, 17:43
This should work:

my_dialog::my_dialog (QWidget* p)
:QDialog(p)
{
setupUi(this);
treeWidget_2->hide();
setMinimumSize( sizeHint() );
}

Marcel

Levon Nikoghosyan
2nd April 2007, 17:48
No this is not works properly, because it sets Minimum size to sizeHint() - correct will be sizeHint()/2

marcel
2nd April 2007, 17:51
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

Levon Nikoghosyan
2nd April 2007, 17:58
Yes I have tried, :(

Levon Nikoghosyan
2nd April 2007, 18:01
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);
}

Levon Nikoghosyan
2nd April 2007, 18:07
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

marcel
2nd April 2007, 18:31
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