【Qt】QML元素:ApplicationWindow与Window

1 Window

Window需要导入QtQuick.Window 。

2 ApplicationWindow

ApplicationWindow需要导入QtQuick.Controls 。

主要区别就是ApplicationWindow提供了简单的方式创建程序窗口,因为其有属性menuBar、toolBar、Tabview等属性,可以方便快速创建一个丰富的窗口。

2.1 界面详情

菜单栏:MenuBar
工具栏:ToolBar
内容区域:Content Area
状态栏:Status Bar
在这里插入图片描述
ApplicationWindow是Window的扩充版,在Window的基础上添加了很多新的元素,如:菜单栏(MenuBar)、工具栏(ToolBar)、状态栏(StatusBar)。

ApplicationWindow {
    id: window
    visible: true

    menuBar: MenuBar {
        Menu { MenuItem {...} }
        Menu { MenuItem {...} }
    }

    toolBar: ToolBar {
        RowLayout {
            anchors.fill: parent
            ToolButton {...}
        }
    }

    TabView {
        id: myContent
        anchors.fill: parent
        ...
    }
}

注:ApplicationWindow默认情况下是不可见的。

2.2 属性(Properties)

2.2.1 内容项 contentItem: ContentItem

该组数据限制了内容项(content item)的尺寸。这个区域在工具栏和状态栏之间。共含有留个属性值分别描述最小(minimum)、隐式(impliciit)和最大(maximum)尺寸。

属性描述
contentItem.minimumWidth内容项的最小宽度
contentItem.minimumHeight内容项的最小高度
contentItem.implicitWidth内容项的隐式宽度
contentItem.implicitHeight内容向的隐式高度
contentItem.maximumWidth内容向的最大宽度
contentItem.maximumHeight内容向的最大高度

2.2.2 菜单栏 menuBar: MenuBar

在这里插入图片描述

ApplicationWindow {
    ...
    menuBar: MenuBar {
        Menu {
            title: "File"
            MenuItem { text: "Open..." }
            MenuItem { text: "Close" }
        }

        Menu {
            title: "Edit"
            MenuItem { text: "Cut" }
            MenuItem { text: "Copy" }
            MenuItem { text: "Paste" }
        }
    }
}

2.2.3 状态栏 statusBar: Item

状态栏本身不提供布局(layout)方式,需要自己对内容进行布局,如使用RowLayout。

如果状态栏内只包含一项,将要对其所包含的内容进行resize以适应隐式高度。这使其特别适合于布局一起使用。否则,高度将取决于平台的高度。

import QtQuick.Controls 1.2
import QtQuick.Layouts 1.0

ApplicationWindow {
    statusBar: StatusBar {
        RowLayout {
            anchors.fill: parent
            Label { text: "Read Only" }
        }
    }
}

2.2.4 风格 style: Componen

https://doc.qt.io/qt-5/qtquick-controls-styles-qmlmodule.html

2.2.5 工具栏 toolBar: Item

默认情况,该项不显示。

状态栏本身不提供布局(layout)方式,需要自己对内容进行布局,如使用RowLayout。

如果状态栏内只包含一项,将要对其所包含的内容进行resize以适应隐式高度。这使其特别适合于布局一起使用。否则,高度将取决于平台的高度。

ApplicationWindow {
    ...
    toolBar:ToolBar {
        RowLayout {
            anchors.fill: parent
            ToolButton {
                iconSource: "new.png"
            }
            ToolButton {
                iconSource: "open.png"
            }
            ToolButton {
                iconSource: "save-as.png"
            }
            Item { Layout.fillWidth: true }
            CheckBox {
                text: "Enabled"
                checked: true
                Layout.alignment: Qt.AlignRight
            }
        }
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

望天边星宿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值