简体   繁体   English

测试QQuickView(QWindow)是否在Qt 5.0.x中全屏显示

[英]Test if QQuickView (QWindow) is full-screen in Qt 5.0.x

For a QWidget we can test if it is displayed in full-screen with flags() & Qt::WindowFullScreen . 对于QWidget我们可以使用flags() & Qt::WindowFullScreen测试它是否全屏显示。 The same doesn't seem to work with QQuickView (which is a QQuickWindow which is a QWindow ), as QWindow::flags() always returns Qt::WindowMinimized , whatever the reason might be. 这似乎与QQuickView (这是一个QQuickWindowQWindowQWindow ,因为QWindow::flags()总是返回Qt::WindowMinimized ,无论原因是什么。 I display the window using this code: 我使用以下代码显示窗口:

QQuickView w;
w.setSource(...);
w.show(); /* or */ w.showFullScreen();

In Qt 5.1, QWindow::visibility() was introduced. 在Qt 5.1中, QWindow::visibility() It returns a new enum type which contains QWindow::FullScreen and behaves properly. 它返回一个新的枚举类型,其中包含QWindow::FullScreen并且行为正常。

How can I test if a QWindow is shown in full-screen in Qt 5.0.x ? 如何在Qt 5.0.x中全屏显示QWindow I want to implement a "toggle full-screen" function. 我想实现“切换全屏”功能。 Keeping track of the current state seems to be the wrong way (yet it would be a possible work-around). 跟踪当前状态似乎是错误的方式(但这可能是一种可能的解决方法)。 I don't understand why QWindow::flags() returns Qt::WindowMinimized ... 我不明白为什么QWindow::flags()返回Qt::WindowMinimized ...

Code to reproduce issue (press RETURN to see the output of QWindow::flags() ): 重现问题的代码(按RETURN查看QWindow::flags()的输出):

test.qml test.qml

import QtQuick 2.0
Rectangle {
    signal test();
    width: 100; height: 100
    focus: true
    Keys.onReturnPressed: test()
}

main.cpp main.cpp中

#include <QGuiApplication>
#include <QQuickView>
#include <QQuickItem>
#include <QDebug>

class Test : public QObject {
    Q_OBJECT
public slots:
    void test() {
        QQuickItem *item = qobject_cast<QQuickItem*>(sender());
        QQuickWindow *window = item->window();
        qDebug() << window->flags(); // Will print 0x1 == Qt::WindowMinimized
    }
};
int main(int argc, char *argv[])
{
    QGuiApplication a(argc, argv);

    QQuickView w;
    w.setSource(QUrl("...(relative path to the qml file from above)..."));
    w.show(); // Please also test w.showFullScreen();

    QObject::connect(w.rootObject(), SIGNAL(test()),
                     new Test, SLOT(test()));

    return a.exec();
}

#include "main.moc"

test.pro test.pro

QT += quick
TEMPLATE = app
SOURCES += main.cpp

Use method QWindow::windowState() . 使用方法QWindow :: windowState() It returns key Qt::WindowFullScreen that you seek. 它返回您寻找的关键Qt :: WindowFullScreen

bool isFullScreen = w.windowState().testFlag(Qt::WindowFullScreen);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM