首页 动态 > > 正文

天天热资讯!Qt Quick Controls - Wearable Demo实例解析

2023-05-06 19:07:28 来源:QT教程 分享到:

程序运行截图如下:

这个实例主要是用qml玩界面。


(资料图)

main.qml文件以及wearable.qml分别是由ApplicationWindow和StatckView。这个StackView用于做导航相关的。

代码如下:

QQC2.ApplicationWindow {id: window...header: NaviButton {id: homeButton...onClicked: stackView.pop(null)}footer: NaviButton {id: backButton...onClicked: stackView.pop()}QQC2.StackView {id: stackView...onLaunched: stackView.push(page)}}DemoMode {stackView: stackView}DemoModeIndicator {id: demoModeIndicatory: settings.demoMode ? -height : -height * 2anchors.horizontalCenter: parent.horizontalCenterheight: header.heightz: window.header.z + 1}MouseArea {enabled: settings.demoModeanchors.fill: parentonClicked: {// Stop demo mode and return to the launcher page.settings.demoMode = falsestackView.pop(null)}}}

在wearable.cpp中应用QQuickStyle的风格:

QQuickStyle::setStyle(QStringLiteral(\"qrc:/qml/Style\"));

在C++代码中设置QQuickStyle风格是十分灵活的,他作用于整个应用。

通过实现qml/NaviButton.qml接口完成自定义button类型。在wearable.qml中home按钮以及back按钮都是自定义的。使用properties扩展可以实现控制滑动过度的相关功能:

QQC2.AbstractButton {id: buttonproperty int edge: Qt.TopEdgeproperty alias imageSource: image.sourcecontentItem: Image {id: image...}background: Rectangle {...}transform: Translate {Behavior on y { NumberAnimation { } }y: enabled ? 0 : edge === Qt.TopEdge ? -button.height : button.height}}

图标绑定了Qt资源文件:/icons。index.theme文件包含了icon主题的内容:

[Icon Theme]Name=WearableComment=Qt Quick Controls 2 Wearable Demo Icon ThemeDirectories=36x36,36x36@2[36x36]Size=36Type=Fixed[36x36@2]Size=36Scale=2Type=Fixed同样在C++里的main函数中进行设置:QIcon::setThemeName(QStringLiteral(\"wearable\"));Launcher页主要是使用了PathView这个组建。PathView {id: circularViewsignal launched(string page)...model: ListModel {ListElement {title: qsTr(\"World Clock\")icon: \"worldclock\"page: \"WorldClock/WorldClockPage.qml\"}...ListElement {title: qsTr(\"Settings\")icon: \"settings\"page: \"Settings/SettingsPage.qml\"}}delegate: QQC2.RoundButton {...icon.width: 36icon.height: 36icon.name: model.icon...onClicked: {if (PathView.isCurrentItem)circularView.launched(Qt.resolvedUrl(page))elsecircularView.currentIndex = index}}...}

目前官方给出的信息中,个人觉得比较重要的就是这么多,后面将会对代码中的知识点进行分析。

【领 QT开发教程 学习资料, 点击下方链接莬费领取↓↓ ,先码住不迷路~】

点击这里:

关键词:

x 广告

国内油价将迎来下调:国际原油跌破90美元关口

国内油价要大幅下调,可能已经是很快要到来的事情了,因为原油期货价格已经在持续下滑,甚至收回了俄乌冲突以来的涨幅。北京时间5日凌晨,

山西发布知识产权保护和运用规划 促进经济社会高质量发展

加强知识产权保护是完善产权保护制度最重要的内容,也是提高经济竞争力最大的激励。5月16日,省政府印发的《山西省十四五知识产权保护和运

4.2万余名残疾人有了专属辅助器具

市残联辅助器具中心为我提供的这辆轮椅,可以躺可以坐,时间长也不太累。由于交通事故导致高位截瘫,张家口市桥东区重度肢体残疾人边海卧病

大庆航空救援支队张家口驻防队伍圆满完成任务

近日,在跨省驻防460余天,圆满完成北京2022年冬奥会和冬残奥会张家口赛区森林防灭火、应急救援等安保任务后,大庆航空救援支队张家口驻防

张家口宣化区不动产登记中心全面提升登记服务工作效率

在工作人员的指引下,半个小时就办完了,没想到这么方便。近日,在宣化区不动产登记中心,前来办理房屋抵押手续的市民孙淑苗高兴地对记者说

x 广告

Copyright   2015-2022 每日地质网版权所有  备案号:浙ICP备2022016517号-15   联系邮箱:5 146 761 13 @qq.com