Window QML Type

Detailed Description

The Window object creates a new top-level window for a Qt Quick scene. It automatically sets up the window for use with QtQuick graphical types.

A Window can be declared inside an Item or inside another Window, in which case the inner Window will automatically become "transient for" the outer Window, with the outer Window as its transientParent. Most platforms will show the Window centered upon the outer window in this case, and there may be other platform-dependent behaviors, depending also on the flags. If the nested window is intended to be a dialog in your application, you should also set flags to Qt.Dialog, because some window managers will not provide the centering behavior without that flag.

You can also declare multiple windows inside a top-level QtObject, in which case the windows will have no transient relationship.

Alternatively you can set or bind x and y to position the Window explicitly on the screen.

When the user attempts to close a window, the closing signal will be emitted. You can force the window to stay open (for example to prompt the user to save changes) by writing an onClosing handler that sets close.accepted = false unless it's safe to close the window (for example, because there are no more unsaved changes).

 
Sélectionnez
onClosing: (close) => {
    if (document.changed) {
        close.accepted = false
        confirmExitPopup.open()
    }
}

// The confirmExitPopup allows user to save or discard the document,
// or to cancel the closing.

Property Documentation

 

height : int

width : int

x : int

y : int

Defines the window's position and size.

The (x,y) position is relative to the Screen if there is only one, or to the virtual desktop (arrangement of multiple screens).

Not all windowing systems support setting or querying top level window positions. On such a system, programmatically moving windows may not have any effect, and artificial values may be returned for the current positions, such as QPoint(0, 0).

 
Sélectionnez
Window { x: 100; y: 100; width: 100; height: 100 }
Image non disponible

minimumHeight : int

minimumWidth : int

Defines the window's minimum size.

This is a hint to the window manager to prevent resizing below the specified width and height.

maximumHeight : int

maximumWidth : int

Defines the window's maximum size.

This is a hint to the window manager to prevent resizing above the specified width and height.

[read-only] active : bool

The active status of the window.

 
Sélectionnez
Window {
    visible: true

    // here we use the Window.active and Window.palette ordinary properties
    color: active ? palette.active.window : palette.inactive.window
}
See Also

See also requestActivate()

[read-only] activeFocusItem : Item

The item which currently has active focus or null if there is no item with active focus.

color : color

The background color for the window.

Setting this property is more efficient than using a separate Rectangle.

If you set the color to "transparent" or to a color with alpha translucency, you should also set suitable flags such as flags: Qt.FramelessWindowHint. Otherwise, window translucency may not be enabled consistently on all platforms.

[read-only] contentItem : Item

The invisible root item of the scene.

contentOrientation : Qt::ScreenOrientation

This is a hint to the window manager in case it needs to display additional content like popups, dialogs, status bars, or similar in relation to the window.

The recommended orientation is Screen.orientation, but an application doesn't have to support all possible orientations, and thus can opt to ignore the current screen orientation.

The difference between the window and the content orientation determines how much to rotate the content by.

The default value is Qt::PrimaryOrientation.

See Also

See also Screen

[default] data : list<QtObject>

The data property allows you to freely mix visual children, resources and other Windows in a Window.

If you assign another Window to the data list, the nested window will become "transient for" the outer Window.

If you assign an Item to the data list, it becomes a child of the Window's contentItem, so that it appears inside the window. The item's parent will be the window's contentItem, which is the root of the Item ownership tree within that Window.

If you assign any other object type, it is added as a resource.

It should not generally be necessary to refer to the data property, as it is the default property for Window and thus all child items are automatically assigned to this property.

See Also

flags : Qt::WindowFlags

The window flags of the window.

The window flags control the window's appearance in the windowing system, whether it's a dialog, popup, or a regular window, and whether it should have a title bar, etc.

The flags that you read from this property might differ from the ones that you set if the requested flags could not be fulfilled.

 
Sélectionnez
import QtQuick

Window {
    id: mainWindow
    title: "Main Window"
    color: "#456"
    property real defaultSpacing: 10

    property Splash splash: Splash {
        onTimeout: mainWindow.show()
    }

    component Splash: Window {
        id: splash

        // a splash screen has no titlebar
        flags: Qt.SplashScreen
        // the transparent color lets background behind the image edges show through
        color: "transparent"
        modality: Qt.ApplicationModal // in case another application window is showing
        title: "Splash Window" // for the taskbar/dock, task switcher etc.
        visible: true

        // here we use the Screen attached property to center the splash window
        x: (Screen.width - splashImage.width) / 2
        y: (Screen.height - splashImage.height) / 2
        width: splashImage.width
        height: splashImage.height

        property int timeoutInterval: 2000
        signal timeout

        Image {
            id: splashImage
            source: "images/qt-logo.png"
        }

        TapHandler {
            onTapped: splash.timeout()
        }

        Timer {
            interval: splash.timeoutInterval; running: true; repeat: false
            onTriggered: {
                splash.visible = false
                splash.timeout()
            }
        }
    }
}
See Also

modality : Qt::WindowModality

The modality of the window.

A modal window prevents other windows from receiving input events. Possible values are Qt.NonModal (the default), Qt.WindowModal, and Qt.ApplicationModal.

opacity : real

The opacity of the window.

If the windowing system supports window opacity, this can be used to fade the window in and out, or to make it semitransparent.

A value of 1.0 or above is treated as fully opaque, whereas a value of 0.0 or below is treated as fully transparent. Values inbetween represent varying levels of translucency between the two extremes.

The default value is 1.0.

[since 6.0] palette : Palette

This property holds the palette currently set for the window.

The default palette depends on the system environment. QGuiApplication maintains a system/theme palette which serves as a default for all application windows. You can also set the default palette for windows by passing a custom palette to QGuiApplication::setPalette(), before loading any QML.

Window propagates explicit palette properties to child items and controls, overriding any system defaults for that property.

 
Sélectionnez
import QtQuick
import QtQuick.Controls

Window {
    visible: true

    // here we use the Window.active and Window.palette ordinary properties
    color: active ? palette.active.window : palette.inactive.window