2

It is possible to remove the header section in the MainView of an new qml app?

enter image description here

Code:

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!") 
                }
            }
        }
    }
}

If I remove the title: "Hello World"of the Page element the header seems to be gone but then the normal window title has this title:

enter image description here

How can I change only this title and hide the header section?

1 Answer 1

2

As you already know, removing the title prevents the header to be displayed. So the only thing to fix is the title of the root window.

You can do this with the following code (where I change the window.title - after importing 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!")
                }
            }
        }
    }
}

enter image description here

2
  • 1
    Thank you! It works also if I don't import QtQuick.Window 2.0.
    – TuKsn
    Jul 23, 2014 at 16:51
  • Great, I didn't know that. Thanks Jul 23, 2014 at 16:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .