I know that this is discussed all over Internet (I just finished a few hour long Googling), but I still cannot find answer for my question.
Short story:
I need to resize a QMainWindow on certain event, so I cannot use static setup of min/max sizes and size policies.
Long story:
Of course, I tried it myself.
This doesn’t have any effect:
calling resize() on QMainWindow and/or it’s central widgwt
creating own QResizeEvent and calling resizeEvent() on window
creating own geometry by calling QMainWindow::geomentry(), then adjusting according my needs and then setting it back
calling updateGeometry() after everything above
calling adjustSize() after everything above
Only working thing is calling setMaximumSize(). Problem is that window is not updated right away, instead it remains in it’s old size until user moves it (why?). When I try move it using geometry, window is moved, but not resized, it still waits until user moves it with mouse.
When I call showMaximized() and then showNormal(), it will maximize and then resize to needed size, but it’s very, very ugly hack and looks awful.
When I call hide() and then showNormal(), original (wrong) size remains.
(Note that setMaximumSize() is ugly hack too, because I want user to be free to resize the Window, so I wanted to set it back to it’s original value later.)
What exactly I’m trying to achieve:
Main window contains some control elements for rendering something. There is a checkbox “Show results in separate window”. When it’s checked, results are in separate window and when unchecked, it’s on right side of main window. And I want resize the window after unchecking so control GUI’s size would remain instead of ugly stretching. (And I cannot use fixed size for it too, because it’s quite wide and so users with smaller screen (like myself) can shrink it (some parts are in QScrollArea; I moved there are all wide elements which cannot be changed for something less wide so rest of the control is quite ok).
First, I store size of result view widget, then remove it and then I need to shrink window but nothing like setWidth(width() – oldWidthVariable) doesn’t work as I stated above.
So, is there a solution, please?
My environment:
Windows XP, SP3
Qt 4.7
MS Visual C 2008
↧