惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
V
Visual Studio Blog
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
Vercel News
Vercel News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
D
DataBreaches.Net
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
The Cloudflare Blog
宝玉的分享
宝玉的分享
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - 蚂蚁跳楼

博文阅读密码验证 - 博客园 qt 的视频教程 sed 使用 qt dbus 的一入门文章 qt越来越好了 ubuntu - 中文 qt-creator astyle Peizhi qml中打开本地html 捷豹汽车的车载系统 博文阅读密码验证 - 博客园 转一个文章:在腾讯的第一堂产品课 QML的一些基础的区分 qml的一个文章----可以看出状态、动画的使用 博文阅读密码验证 - 博客园 凡是人性的,都是如下的 全国经纬度,具体到县 web-nodkit 入门 一个文章-转年收入50万美元的软件工程师做的是什么类型的工作 一个基于qml的网络封装库
qml 封装技巧-利用数据来进行适配
蚂蚁跳楼 · 2015-05-14 · via 博客园 - 蚂蚁跳楼

Text属于用的频率比较高而且需要定义的地方又比较多的地方,看一下如下的把Text封装成Label进行使用。

使用的例子:
Label {
id: titleLabel

anchors {
left: parent.left
right: parent.right
margins: units.dp(16)
}

style: "title"
text: "Edit info"
}

封装的原始代码:

import QtQuick 2.0

Text {
id: label
property string style: "body1"

property var fontStyles: {
"display4": {
"size": 112,
"font": "light"
},

"display3": {
"size": 56,
"font": "regular"
},

"display2": {
"size": 45,
"font": "regular"
},

"display1": {
"size": 34,
"font": "regular"
},

"headline": {
"size": 24,
"font": "regular"
},

"title": {
"size": 20,
"font": "medium"
},

"dialog": {
"size": 18,
"size_desktop": 17,
"font": "regular"
},

"subheading": {
"size": 16,
"size_desktop": 15,
"font": "regular"
},

"body2": {
"size": 14,
"size_desktop": 13,
"font": "medium"
},

"body1": {
"size": 14,
"size_desktop": 13,
"font": "regular"
},

"caption": {
"size": 12,
"font": "regular"
},

"menu": {
"size": 14,
"size_desktop": 13,
"font": "medium"
},

"button": {
"size": 14,
"font": "medium"
},

"tooltip": {
"size_desktop": 10,
"size": 14,
"font": "medium"
}
}

property var fontInfo: fontStyles[style]

font.pixelSize: units.dp(!Device.isMobile && fontInfo.size_desktop
? fontInfo.size_desktop : fontInfo.size)
font.family: "Roboto"
font.weight: {
var weight = fontInfo.font

if (weight === "medium") {
return Font.DemiBold
} else if (weight === "regular") {
return Font.Normal
} else if (weight === "light") {
return Font.Light
}
}

font.capitalization: style == "button" ? Font.AllUppercase : Font.MixedCase

color: Theme.light.textColor

}