首页 > 解决方案 > 在全屏和窗口模式之间切换

问题描述

我的问题与这个有关:Full-screen desktop application with QML

这是我的 MWE:

import QtQuick 2.11
import QtQuick.Window 2.2
import QtQuick.Controls 2.2

Window
{
    property string windowFull: "FullScreen";
    property string windowWindowed: "Windowed";

    width: 400
    height: 400
    visible: true
    title: "Example"
    visibility: windowFull;
    id: theWindow;

    Button
    {
        onClicked:
        {
            if (theWindow.visibility === windowWindowed)
                theWindow.visibility = windowFull;
            else
                theWindow.visibility = windowWindowed;
        }
    }
}

在此示例中,我尝试在单击按钮时从窗口模式切换到全屏模式,反之亦然。我的问题是从窗口模式进入全屏工作,但从全屏到窗口不工作。为了从全屏进入窗口模式,是否有任何特殊要求?

标签: qtqml

解决方案


在 Ubuntu 上,使用Window.AutomaticVisibility将窗口可见性设置为窗口(默认窗口)。请检查QML 窗口示例

import QtQuick 2.11
import QtQuick.Window 2.2
import QtQuick.Controls 2.2

Window
{
    property string windowFull: "FullScreen";
    property string windowWindowed: "Windowed";

    width: 400
    height: 400
    visible: true
    title: "Example"
    visibility: windowFull;
    id: theWindow;

    Button
    {
         onClicked:
        {
            if (theWindow.visibility === Window.FullScreen)
                theWindow.visibility = Window.AutomaticVisibility;
            else
                theWindow.visibility = Window.FullScreen;
        }
    }
}

推荐阅读