PDA

View Full Version : minimizing main window



eric
28th November 2007, 16:37
Hi all! I was wondering if anybody could recommend how to always keep the main window (main layout) as minimal as possible for whatever it countains even if the size of its content changes.
More specifically: My window size is not pre-determined. My window (main layout) contains a QLabel. So, first the window assumes a minimal size to accomodate the QLabel and that's what I want. As the program runs, the QLabels is getting smaller. Now I want the window to automatically contract to the smallest possible size but my window retains its original size. So far it can only expand, not contract. How do I make it contract? I guess I need to somehow refresh the main window but I don't know how.
Always thankful for your ideas. eric

jpn
28th November 2007, 16:52
You can either call QWidget::adjustSize() by hand or if you're willing to make the window fixed size, you can do
window->layout()->setSizeConstraint(QLayout::SetFixedSize); and it will automatically follow size hint changes.

eric
28th November 2007, 17:10
Thank you jpn!
The below code still won't make the window to always assume the smallest size possible. I may have understood you wrong or maybe I should remove all the addStretch() lines from my constructor code?



int main(int argc, char *argv[])
{
QApplication application(argc, argv);
MyWidget window;
window.adjustSize();
window.show();
return application.exec();
}


I don't want to make the window fixed size, I'd like it to be collapsible.

jpn
28th November 2007, 17:21
You would have to call adjustSize() every time the size changes. This is what I meant with "by hand".

eric
28th November 2007, 17:54
I got you, but I can't put the code


window.adjustSize();

in the function (which is in a separate file) that causes the need for window resizing - the code won't compile. I get "not enough contextual info" error message. Apparently the other functions don't know what "window" is. Window is only declared in the main() function and is not part of my *.h file. Does "window" have to be in the *.h file in order for the above line to work? I don't think I could create "window" anywhere else than the main function?
So you say that it is not possible to make the main function always check the size of the window and see if it could possibly be made smaller?