irpas技术客

QML 之 button 修改字体颜色,ButtonStyle的使用方式_比卡丘不皮_button字体颜色

网络 1330

在QML 中,我们使用Button 这个控件的话,没有设计的话就会出现如下:

?那我们想改变样式的话,就要使用style:ButtonStyle,我们点击帮助文档,看到例子只写了background。

我们就模仿写出来它的lable。

写出来效果:

对应代码:

Button{ id:button1; width: 80; height: 80; anchors.left: rect2.right; anchors.leftMargin: 20; anchors.top: rect2.top; text: "quit"; style: ButtonStyle{ background: Rectangle{ implicitWidth: 40; implicitHeight: 30; color: "red" border.width: control.pressed? 5:3; border.color: (control.hovered || control.pressed) ? "green":"#888888"; } label: Item { anchors.fill: parent; Text { text: button1.text; anchors.centerIn: parent; color: "blue"; font.pixelSize: 20; font.weight: Font.DemiBold } } } onClicked: { Qt.quit(); } }

?

?


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #button字体颜色 #在QML #中我们使用Button #我们就模仿写出来它的lable #写出来效果对应代码Button