QML中自定义button按钮
在qml中自定义button控件需要用到ButtonStyle,头文件要引入QtQuick.Controls.Styles
本文以定义一个多边形按钮为例,实现效果
实现代码
在这里插入代码片
`import QtQuick 2.12
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
Window {
id: mainWindow
visible: true
width: 800
height: 480
title: "GMS/EDGE"
Button {
id: bt0_1
width: mainWindow.width / 8
height: 86
anchors.top: mainWindow.top//按钮布局
anchors.left: mainWindow.left
anchors.leftMargin: 1
activeFocusOnPress: true
style: ButtonStyle {
background: Rectangle {
height: bt0_1.height
color: {
if (bt0_1.activeFocus) {//如果按钮获焦点则显示"#93A7B4"颜色否则显示 "#DBE2E6&#