[solved] (OSX) resizing the QMainWindow
-
I have a problem with a C++/Qt5 (Qt 5.4 on OSX) project, written for Linux but also tested on OSX (10.10.1). I have only encountered this error on OSX.
When I start my program ("DipylonReader":https://github.com/suizokukan/dipylonreader), a window appears with the menu above and a window containing the infamous three icons red/orange/green, a toolbar and an empty widget : that's my QMainWindow.
!http://94.23.197.37/hostedimages/1/screenshot1.png(DipylonReader on OSX : menu, tool bar, QMainWindow)!
I if use the orange/green buttons, everything's works as expected.
Now, I added an icon of my own to give a special size to the main window. Here's my code, triggered when the user presses this button :
@
void MainWindow::xyz__buttonPressed(void) {
QSize size = QGuiApplication::primaryScreen()->size();
size.setWidth(size.height()/2);
size.setHeight(size.height());
this->move((size.width() / 2), 0);
this->resize(size);
}@This code works well (the QMainWindow becomes smaller), except if the user has previously pressed the "green" icon, thus maximazing the QMainWindow. In this special case, the screen becomes black (no more main menu, no more desktop), the QMainWindow appears but not at the expected place :
!http://94.23.197.37/hostedimages/1/screenshot2.png(QMainWindow on a black screen)!
I tried to add the following line at the beginning of my function, without any success :
@// leaving the full screen mode :
this->showNormal();@I obviously doesn't understand how Qt works on OSX. Any help would be appreciated !
-
This:
@void MainWindow::xyz__buttonPressed()
{
showNormal();
QSize size = QGuiApplication::primaryScreen()->size();
size.setWidth(size.height()/2);
size.setHeight(size.height());
this->move((size.width() / 2), 0);
this->resize(size);
}
@works without an issue for me. Qt 5.3.2.
-
sandy.martel : thank you. I think I got it : the following line :
@this->showNormal();@is mandatory, despite what I wrote previously. I tested my code with and without this line, which makes the difference.