QT 5.3 Mac全屏

时间:2014-06-17 14:28:46

标签: c++ macos qt fullscreen

我试图将我的应用程序设置为全屏并返回到Qt 5.3,但我在Mac上遇到了一些问题。当我使用showFullScreen()时,它会按预期进入全屏状态。它使用标准的Mac全屏模式,在单独的桌面/空间中打开。但是,当我呼叫showNormal()从全屏模式返回时,应用程序窗口就会消失,我将以灰色背景离开。我需要滑动才能返回应用程序所在的常规桌面。

这是Qt中的错误还是我做错了什么?我是OS X 10.9.3。

3 个答案:

答案 0 :(得分:1)

我在Mac OS X上遇到与Qt 5.2类似的问题(但不是Qt 4.8)。这似乎解决了这个问题:

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
}

答案 1 :(得分:0)

我不确定thisthis是否与您的问题有关。但似乎调用showFullScreen()showNormal()在Mac上出现问题。

您可以使用showFullScreen()将来电更改为showNormal()setWindowState()

showFullScreen();可以更改为

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

showNormal();可以更改为

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

答案 2 :(得分:0)

这是一个在我的系统上正常工作的简单示例应用程序(Qt 5.3.1,MacOS / X 10.9.5)。它也适用于你吗?如果是这样,请尝试找出该程序与程序之间的不同之处。

在调用showNormal()之后,您也可以尝试调用show(),raise()和activateWindow(),看看这些是否有用。

// 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

...和.cpp文件:

// 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();
}