删除 Ubuntu SDK 上 qml 应用程序中的标头部分

删除 Ubuntu SDK 上 qml 应用程序中的标头部分

是否可以删除新 qml 应用程序 MainView 中的标题部分?

在此处输入图片描述

代码:

import QtQuick 2.0
import Ubuntu.Components 0.1
import "components"

/*!
    \brief MainView with a Label and Button elements.
*/


MainView {
    width: 400
    height: 400
    transformOrigin: Item.Center
    clip: false
    opacity: 1

    // objectName for functional testing purposes (autopilot-qt5)
    objectName: "mainView"

    // Note! applicationName needs to match the "name" field of the click manifest
    applicationName: "com.ubuntu.developer.username.hello1"


    Page {
        id: page1
        clip: false
        title: "Hello World"

        Column {
            id: column1
            anchors.bottomMargin: 45
            spacing: units.gu(1)
            anchors {
                margins: units.gu(2)
                fill: parent
            }

            HelloComponent {
                id: label
                height: 50
                objectName: "label"

                text: i18n.tr("Hello..")
                anchors.left: parent.left
                anchors.leftMargin: 0
                anchors.right: parent.right
                anchors.rightMargin: 0
            }

            Button {
                objectName: "button"
                width: parent.width

                text: i18n.tr("Tap me!")

                onClicked: {
                    label.text = i18n.tr("..world!") 
                }
            }
        }
    }
}

如果我删除title: "Hello World"页面元素,标题似乎消失了,但正常窗口标题有这个标题:

在此处输入图片描述

我怎样才能仅更改此标题并隐藏标题部分?

答案1

正如您所知,删除标题会导致无法显示标题头。因此,唯一需要修复的是根窗口的标题。

您可以使用以下代码执行此操作(我window.title在导入后更改了 - QtQuick.Window):

import QtQuick 2.0
import Ubuntu.Components 0.1
import QtQuick.Window 2.0

/*!
    \brief MainView with a Label and Button elements.
*/


MainView {
    width: 400
    height: 400
    transformOrigin: Item.Center
    clip: false
    opacity: 1

    // objectName for functional testing purposes (autopilot-qt5)
    objectName: "mainView"

    // Note! applicationName needs to match the "name" field of the click manifest
    applicationName: "com.ubuntu.developer.username.hello1"


    Page {
        id: page1
        clip: false
        property var my_title: "Hello World"

        // 'window' is defined by QML between startup and showing on the screen.
        // There is no signal for when it becomes available and re-declaring it is not safe.
        property bool windowActive: typeof window != 'undefined'
        onWindowActiveChanged: {
            window.title = my_title
        }

        Column {
            id: column1
            anchors.bottomMargin: 45
            spacing: units.gu(1)
            anchors {
                margins: units.gu(2)
                fill: parent
            }

            Text {
                id: label
                height: 50
                objectName: "label"

                text: i18n.tr("Hello..")
                anchors.left: parent.left
                anchors.leftMargin: 0
                anchors.right: parent.right
                anchors.rightMargin: 0
            }

            Button {
                objectName: "button"
                width: parent.width

                text: i18n.tr("Tap me!")

                onClicked: {
                    label.text = i18n.tr("..world!")
                }
            }
        }
    }
}

在此处输入图片描述

相关内容