How to put MainView into maximized

5,321

Solution 1

To maximize your window, given that your target is a desktop app, I would rely on standard shortcuts like a double click on the title bar. Of course there's the window decoration controls too.

To start maximized, you can use the Screen properties:

import QtQuick 2.0
import QtQuick.Window 2.0

Rectangle {
    width: Screen.width
    height: Screen.height
    border.color: "lime"
    border.width: 15
    color: "transparent"
    Text {
        anchors.centerIn: parent
        text: Screen.width + " x " + Screen.height
        font.bold: true
        font.pointSize: 80
        color: "lime"
        smooth: true
    }
}

Only Qt5.1 offers fine control on such window operations though: Visit http://qt-project.org/doc/qt-5.1/qtquick/qml-qtquick-window2-window.html#visibility-prop

Alternatively to maximize the view, you can export a C++ function that will call QWidget::showMaximized() for you and then call it from QML.

Solution 2

Just use visibility:

visibility: "Maximized"

The doc reads as:

visibility : QWindow::Visibility

The screen-occupation state of the window.

Visibility is whether the window should appear in the windowing system as normal, minimized, maximized, fullscreen or hidden.

To set the visibility to AutomaticVisibility means to give the window a default visible state, which might be fullscreen or windowed depending on the platform. However when reading the visibility property you will always get the actual state, never AutomaticVisibility.

When a window is not visible its visibility is Hidden, and setting visibility to Hidden is the same as setting visible to false.

Also, know the possible values for this attribute.

Share:
5,321

Related videos on Youtube

Paholaisen Kysymys
Author by

Paholaisen Kysymys

Trying to produce something beautiful with ubuntu sdk. Trying to qml Trying to stay sane

Updated on September 18, 2022

Comments

  • Paholaisen Kysymys
    Paholaisen Kysymys almost 2 years

    [using ubuntu sdk to write an application for the desktop]

    Is there a way to change the window state of the MainView?

    MainView {
        ...
    
        width: units.gu(100)
        height: units.gu(75)
    
        Page {
            Button {
                anchors.centerIn: parent
                width: units.gu(30)
                height: units.gu(10)
                text: "Maximize this window"
    
                onClicked: {
                    // Do something that maximizes the window
                }
            }
        }
    }