qt-Quick笔记之Dark Mode And Light Mode In Application

devtools/2025/2/5 18:34:32/

qtQuickDark_Mode_And_Light_Mode_In_Application_0">qt-Quick笔记之Dark Mode And Light Mode In Application

code review!

文章目录

  • qt-Quick笔记之Dark Mode And Light Mode In Application
    • 1.运行
    • 2.目录结构
    • 3.main.qml
    • 4.main.cpp
    • 5.main.pro
    • 6.main.qrc

本例修改自视频教程:Qt QML | 🌙 Dark Mode And ☀️ Light Mode In Application
链接:https://www.youtube.com/watch?v=O-UoB62uxlA

1.运行

在这里插入图片描述

2.目录结构

.
├── main.cpp
├── main.qml
├── main.qrc
└── test3.pro1 directory, 4 files

3.main.qml

import QtQuick
import QtQuick.Controls
import QtQuick.LayoutsWindow {id: mainWindowwidth: 640height: 480title: "DarkMode And LightMode"color: appTheme.backgroundColorvisible: trueQtObject {id: appThemeproperty color backgroundColor: "#FFFFFF"property color textcolor: "#2f3640"property color buttontextcolor: "#FFFFFF"property color buttonbackgroundcolor: "#2f3640"function setLightTheme() {backgroundColor = "#FFFFFF"textcolor = "#2f3640"buttontextcolor = "#FFFFFF"buttonbackgroundcolor = "#2f3640"}function setDarkTheme() {backgroundColor = "#2f3640"textcolor = "#FFFFFF"buttontextcolor = "#2f3640"buttonbackgroundcolor = "#FFFFFF"}}ColumnLayout {anchors.centerIn: parentText {Layout.preferredWidth: 200Layout.preferredHeight: 100Layout.alignment: Qt.AlignHCenterid: myTexttext: qsTr("Qt With Ketan")color: appTheme.textcolorfont.pointSize: 20}Button {Layout.preferredWidth: 200Layout.preferredHeight: 100Layout.alignment: Qt.AlignHCenterid: myButtonText {text: "Qt With Ketan"color: appTheme.buttontextcoloranchors.fill: parenthorizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignVCenter}background: Rectangle {color: appTheme.buttonbackgroundcolorradius: 20}}}Switch {id: themeSwitchtext: "Light Mode"anchors.top: parent.topanchors.horizontalCenter: parent.horizontalCenterchecked: falsecontentItem: Text {text: themeSwitch.checked ? "Dark Mode" : "Light Mode"color: appTheme.textcolorverticalAlignment: Text.AlignVCenterleftPadding: themeSwitch.indicator.width + themeSwitch.spacingfont.pointSize: 15}onCheckedChanged: {if (checked) {appTheme.setDarkTheme()} else {appTheme.setLightTheme()}}}Component.onCompleted: appTheme.setLightTheme()
}

4.main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>int main(int argc, char *argv[])
{QGuiApplication app(argc, argv);QQmlApplicationEngine engine;engine.load(QUrl(QStringLiteral("qrc:/main.qml")));return app.exec();
}

5.main.pro

QT += quickSOURCES += \main.cppresources.files = main.qml 
resources.prefix = /$${TARGET}
RESOURCES += main.qrc# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

6.main.qrc

<RCC><qresource prefix="/"><file>main.qml</file></qresource>
</RCC>

http://www.ppmy.cn/devtools/156350.html

相关文章

Dest1ny攻防实战:SpringBoot 脱敏属性***明文获取

今天是dest1ny攻防实战&#xff01; 脱敏springboot敏感数据&#xff01;&#xff01; 大家多多支持&#xff0c;多多点赞&#xff0c;多多关注&#xff01;&#xff01; 谢谢大家&#xff0c;下面我们来看今天的内容&#xff01; 1.前言 SpringBoot敏感信息泄露&#xff0…

8266使用websocket库

安装 WebSocket 库 使用 Arduino IDE 安装&#xff1a; 打开 Arduino IDE。转到 Sketch > Include Library > Manage Libraries...。在搜索框中输入“WebSockets”并查找 WebSockets by Markus Sattler 的库。点击安装。 最下面那个&#xff0c;安装编译运行测试&#…

4 前端前置技术(中):node.js环境

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言 前言

【设计测试用例自动化测试性能测试 实战篇】

&#x1f308;个人主页&#xff1a;努力学编程’ ⛅个人推荐&#xff1a; c语言从初阶到进阶 JavaEE详解 数据结构 ⚡学好数据结构&#xff0c;刷题刻不容缓&#xff1a;点击一起刷题 &#x1f319;心灵鸡汤&#xff1a;总有人要赢&#xff0c;为什么不能是我呢 设计测试用例…

STM32 LED呼吸灯

接线图&#xff1a; 这里将正极接到PA0引脚上&#xff0c;负极接到GND&#xff0c;这样就高电平点亮LED&#xff0c;低电平熄灭。 占空比越大&#xff0c;LED越亮&#xff0c;占空比越小&#xff0c;LED越暗 PWM初始化配置 输出比较函数介绍&#xff1a; 用这四个函数配置输…

蓝桥杯备考:高精度算法之乘法

P1303 A*B Problem - 洛谷 | 计算机科学教育新生态 在这里&#xff0c;我们模拟乘法过程的时候要用无进制相加 相加完之后就是4 13 28 27 18 我们从最低位开始不断往上进位&#xff0c;18%10就是8留下&#xff0c;18/101是进位&#xff0c;28%10 是8留下&#xff0c;2…

Go方法接收者中值类型接收者和指针类型接收者的对比

这是一个很好的问题。选择值类型接收者还是指针类型接收者确实需要权衡。让我们详细探讨一下&#xff1a; 值类型接收者&#xff1a; 当方法不需要修改接收者的状态时。当接收者是一个小的结构体或者是基本类型时。当你需要复制接收者的值时&#xff08;例如&#xff0c;在并…

C# 修改项目类型 应用程序程序改类库

初级代码游戏的专栏介绍与文章目录-CSDN博客 我的github&#xff1a;codetoys&#xff0c;所有代码都将会位于ctfc库中。已经放入库中我会指出在库中的位置。 这些代码大部分以Linux为目标但部分代码是纯C的&#xff0c;可以在任何平台上使用。 源码指引&#xff1a;github源…