PDA

View Full Version : Custom maximization



maverick_pol
21st May 2009, 22:22
Hi guys,

I need to have a main window which can only maximize in height.
The problem is that when I set a fixed width the maximize button is disabled.
I need that button enabled to fit the window vertically in the screen.
How to set a fixed width and still have a maximize button enabled?

Thanks you

maverick_pol
21st May 2009, 23:23
Any idea?
To sum up, I would like to have a fixed width and the maximize button to fit the window in height on the screen.
Thank you for any hints.

Kacper

wysota
22nd May 2009, 00:02
I don't think this is possible on Qt level. Maybe there is some hint you might pass to the window manager while creating a widget but I doubt that. You would probably have to use the native API for this. You can try emulating the effect by resizing the window to previous width after detecting maximization.

aamer4yu
22nd May 2009, 05:33
Or you can resize your window to limits on resizeEvent :rolleyes:

maverick_pol
22nd May 2009, 08:52
Yes, I have already tried working with the resizeEvent and maximization.

Thank you for the hints.

maverick_pol
22nd May 2009, 09:03
Ok,

Last question:

I can implement my own resizeEvent(..), but I can't call the resize() or setGeometry() in the event due to infinite recursion, am I right?
Howto set the size in the resize event then?
I can get the old size and new size, set old width and only update the height. But which method to use inside resizeEvent?

Thank you

wysota
22nd May 2009, 09:20
I can implement my own resizeEvent(..), but I can't call the resize() or setGeometry() in the event due to infinite recursion, am I right?

You can. Just have a stop condition - i.e. if you want to resize to a size that is already set, don't call resize().

maverick_pol
22nd May 2009, 10:02
would this make sense? I get a recursion here(resizeEvent body)



QSize oldSize = event->oldSize();
QSize newSize = event->size();
if(oldSize!=newSize)
{
resize(oldSize.width(),newSize.height());
event->accept();
}
event->ignore();


I am also looking for a signal to detect maximization. Is there any signal connected with this action? Should I overide the "showMaximixed()" slot in my mainwindow?
How to detect the maximize action?

THANK YOU

wysota
22nd May 2009, 11:56
would this make sense?
Not really. You have to calculate the new-new-size yourself and compare it to the new-size that you get from the event.



I am also looking for a signal to detect maximization. Is there any signal connected with this action? Should I overide the "showMaximixed()" slot in my mainwindow?
How to detect the maximize action?
Yes, you can do that this way, but it will only work if someone calls showMaximized() and not when an appropriate button on the window's decoration is used.

maverick_pol
22nd May 2009, 13:01
Hi,

Thank you for the detailed explaination. This is my last question:

How to detect the maximize button click ?

Thank you

wysota
22nd May 2009, 20:33
I guess you'd have to listen for native events but I can't guarantee there is one sent on each of the supported platforms.

aamer4yu
23rd May 2009, 12:21
You can override winEvent of your widget, and modify the size there.
I remember seeing a code where they had done something like this. You will need to modify the MSG structure parameters