How to maximize main window to full screen in Mac OSX and Windows OS ?
-
I am new to Qt. I am using Qt 4.8.3 library , Mac OSX 10.8 and windows 7.
I have to fix the problem of maximizing the window to full screen when the user clicks on "Maximize" button on menu bar.
I wanted to fix it within "mainwindow.ui" (rather than "ui_mainwindow.h" , only because it is generated code and all the changes made here will be lost in recompile). I tried playing around with the property "maximumSize" for main window.I tried to remove this property, set the values to "0" etc. - but nothing works on Mac OSX 10.8. Even I tried with generated file "ui_mainwindow.h" by commenting out "MainWindow->setMaximumSize()" but it did not work. I mean, the effect was, the main window simply disappeared and nothing visible on the screen.
However, I found that for Windows (windows 7 and XP), if I commented out "MainWindow->setMaximumSize()" , it worked as desired.
My question is - how can I maximize the main window to full screen for Mac OSX and Windows , preferably using mainwindow.ui and not from "ui_mainwindow.h"?
-
You will likely need methods (slots) like show *:
@
void QWidget::show()
void QWidget::showFullScreen()
void QWidget::showMaximized()
void QWidget::showMinimized()
void QWidget::showNormal()
@You worked with them?
-
I don't exactly know what is the problem. Why do you ask for guidance on maximizing the window, but are trying to set the max size to 0? By default, sizing policy if set to be flexible, and ma window size is set to a huge number (I don't remember exactly how big it was).
Or maybe you want to start the app maximized? Then you can use the method "QWidget::showMaximized()":http://qt-project.org/doc/qt-4.8/qwidget.html#showMaximized in your code.
-
Thank you Konatatin. No , I have never worked with them.May I get any link for sample code /examples for these methods ? The key is , it should work both on Windows and Mac . I do not mind having two separate code for these platforms, if required.
Many, many thanks Sierdzio for reply. The problem is, when I click on "maximize" icon, the size should be set to full screen.That, I want to do preferably using "mainwindow.ui" and not by any modification in generated file "ui_mainwindow.h”. You said, if the "sizing policy" is set to "default" and window size is set toa huge number , it should work oth for Windows and Mac? Surely, it is worth trying.
I don't want the app to star maximized. But it should respond to "maximize" icon click and set to full screen. -
As long as you don't set size policy to "Fixed" it should work well on all platforms. Please be aware, though, that Mac platform does not work as sane people expect it to - the maximize button does not work the same way as on Linux or Windows. Check with other apps - you will not get it to maximize under every circumstance.
And BTW. it is never required to modify anything in generated "ui_*" files. Everything can be done in .ui or c++ behind it.