PDA

View Full Version : resize Dialog to minimum height



pospiech
28th April 2009, 15:35
I have a dialog with a tabwidget which can be enabled or disabled (hidden)

If the tabwidget is hidden the dialog must not take the whole space it
had with the tabwidget.
It should rather be resized to minimum height. this however did not
work. I tried the following:


if (state == Qt::Checked)
tabWidget_FullOptions->setHidden(false);
else {
tabWidget_FullOptions->setHidden(true);
this->resize(this->sizeHint().width(),
this->minimumSizeHint().height());
}

However the resize does not happen, or has no effect.
So how do I resize a Dialog to its minimum height?

Matthias

wysota
28th April 2009, 19:55
You can only do that automatically by setting a size constraint on its layout.

pospiech
28th April 2009, 20:09
You can only do that automatically by setting a size constraint on its layout.
Sorry, I have no idea what you mean. Can you give me a hint towards the corresponding function in QWidget?

Lykurg
28th April 2009, 20:22
As a normal procedure one should open assistant and use its search function. As you was told something about "size" and "constraint" try to use the phrases "sizeconstraint" or "constraintsize" and as you want to set this try "setsizeconstraint" or "setconstraintsize". One will lead you to the function!

Or may you look at our wiki (searching "dialog"): Expanding dialog (http://wiki.qtcentre.org/index.php?title=Expanding_dialog)

wysota
28th April 2009, 21:06
Sorry, I have no idea what you mean. Can you give me a hint towards the corresponding function in QWidget?

If you are posting a question in the section of the forum called "Qt Programming" and your profile states you are an intermediate Qt user, I'm assuming you know how to use Qt Assistant, how to write C++ code and how to solve basic problems related to your programs. If you don't fall into this category and you want a direct solution, please instead post in the "Newbie" forum which is there for the purpose. If you know how to handle a fishing pole, post in Qt Programming. If you're only after the fish, post in the Newbie section.

Sorry for being so rude and straightforward but the amount of questions asking for direct solutions has recently increased significantly and of course nobody considers himself a newbie. So consider this a moderator message, not a regular board user reply.

pospiech
29th April 2009, 08:36
Or may you look at our wiki (searching "dialog"): Expanding dialog (http://wiki.qtcentre.org/index.php?title=Expanding_dialog)
You mean:


layout()->setSizeConstraint(QLayout::SetFixedSize);

Well, I was asking because it was not in the list of QWidget functions, but looking deeper it shows up in QLayout.

This does the resizing. However also in width, and sets the size to fixed. That is much more than I wanted. I wanted it to be resized to minimum height without changes to the size constrain. If that is not possible I could live with size constrain.


If you are posting a question in the section of the forum called "Qt Programming" and your profile states you are an intermediate Qt user, I'm assuming you know how to use Qt Assistant, how to write C++ code and how to solve basic problems related to your programs.
First of all, yes I agree with you. If you feel that trivial questions (rating of trivial though is difficult to measure) should only be placed in the Newbie section I do not mind if you move the thread. But what did I do - I provided my inital trial, and asked for a solution and would implicitly like to know why mine did not work. Your answer introduced a complete concept of Qt of handling things. I responded because I did not see the connection to my question.

And yes I had looked into the documentation (QAssistent). But the docs very seldom provides solutions to problems (still they are a superb reference).
Here I found several functions dealing with the Size. So for example there are:
- void adjustSize ()
- void resize ( const QSize & )

I did not understand what the first does, so I tried the second. And in my post I explained how I had tried to get a solution. Size Constrain is a concept I had no heard of before

Now I know that there is a size constrain thing, but I still do not know how to resize to minimum height, without changing the size constrain.

wysota
29th April 2009, 10:21
Well, I was asking because it was not in the list of QWidget functions, but looking deeper it shows up in QLayout.
That's why I said to set a constraint on a layout.


This does the resizing. However also in width, and sets the size to fixed. That is much more than I wanted. I wanted it to be resized to minimum height without changes to the size constrain. If that is not possible I could live with size constrain.
You can set a different size constraint...


And yes I had looked into the documentation (QAssistent). But the docs very seldom provides solutions to problems (still they are a superb reference).
Sure they do, people just look in one place and if don't find the solution there, they assume it can't be nowhere else too. Using the search in Assistant (and not only the index) often helps but most people don't bother trying.


Now I know that there is a size constrain thing, but I still do not know how to resize to minimum height, without changing the size constrain.

You can always call

resize(width(), minimumSizeHint().height());
but you have to do that manually.

pospiech
25th June 2009, 14:04
Any resizing does not work anymore, after I made the dialog to a Mdisubwindow.

Now with the size constrain meantioned here, the widget is with correct height, but centered into the Dialog window with 200px above and below left empty.

If I set the widget to full size (make the hidden part visible) it takes the space available before.

If I use resize with 'minimumSizeHint().height()', then the height value changes between 300 and 700 but the resize command has no effect.

The reason for this error, is that all commands apply to the widget, not the surrounding Dialog.

So how do I ensure that the dialog (from QMdiSubWindow) is resized and not only the containing widget?