8
votes

I'm trying to set my application to full screen and back in Qt 5.3, but I'm running into some issues on Mac. When I use showFullScreen(), it goes into full screen as expected. It uses the standard Mac full screen mode where it opens in a separate desktop/space. However, when I call showNormal() to return from full screen mode, the application window just disappears and I'm left with a gray background. I need to swipe in order to return to the regular desktop where the application is.

Is this a bug in Qt or am I doing something wrong? I'm on OS X 10.9.3.

3

3 Answers

1
votes

I had similar problems with Qt 5.2 on Mac OS X (but not Qt 4.8). This seems to fix it:

if ( showFullScreen )
{
    widget->setParent( NULL );
    widget->showFullScreen();
}
else
{
    // changing the order of the showNormal() and setParent() results in a grey screen in Qt 5 on Mac
    widget->showNormal();
    widget->setParent( widgetParent ); // reset the original parent
}
0
votes

I am not sure if this or this relate to your problem. But it seems that calls to showFullScreen() and showNormal() is buggy on Mac.

You can change the calls to showFullScreen() and showNormal() with setWindowState().

showFullScreen(); can be changed to

setWindowState(windowState() | Qt::WindowFullScreen);

And showNormal(); can be changed to

 setWindowState(windowState() & ~Qt::WindowFullScreen);
0
votes

Here's a trivial example application that works correctly on my system (Qt 5.3.1, MacOS/X 10.9.5). Does it work correctly for you also? If so, try and figure out what is different between this program and your program.

You might also try calling show(), raise(), and activateWindow() after calling showNormal() and see if those things help.

// MyWindow.h
#ifndef MYWINDOW_H
#define MYWINDOW_H

#include <QAction>
#include <QLabel>
#include <QTimer>
#include <QTime>
#include <QMainWindow>

class MyWindow : public QMainWindow
{
Q_OBJECT

public:
   MyWindow();

private slots:
   void goFS();
   void goNormal();

private:
   QAction * fsAct;
   QAction * normAct;
};

#endif // MYWINDOW_H

... and the .cpp file:

// MyWindow.cpp
#include <QApplication>
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include "MyWindow.h"

MyWindow :: MyWindow()
{
   fsAct = new QAction(tr("Full Screen Mode"), this);
   connect(fsAct, SIGNAL(triggered()), this, SLOT(goFS()));

   normAct = new QAction(tr("Normal Mode"), this);
   connect(normAct, SIGNAL(triggered()), this, SLOT(goNormal()));
   normAct->setEnabled(false);

   QMenuBar * mb = menuBar();
   QMenu * modeMenu = mb->addMenu(tr("ScreenMode"));
   modeMenu->addAction(fsAct);
   modeMenu->addAction(normAct);
}

void MyWindow :: goFS()
{
   normAct->setEnabled(true);
   fsAct->setEnabled(false);

   showFullScreen();
}

void MyWindow :: goNormal()
{
   normAct->setEnabled(false);
   fsAct->setEnabled(true);

   showNormal();
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    MyWindow scr;
    scr.show();

    return a.exec();
}