import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
Window {
width: 640
height: 480
color: "white"
title: qsTr("My QML")
visible: true
//自定义Button
Button{
id:btn
width:150
height: 100
background: Rectangle{
anchors.fill: parent
color: btn.checked | btn.down?"blue":"black"
}
}
//自定义按钮重绘Text
Button{
y:80
id:control
text: qsTr("Button")
contentItem: Text {
text: control.text
//加粗
font.bold: true
//大小
font.pixelSize: 18
//斜体
font.italic:true
}
}
//自定义按钮重绘Rectangle
Button{
y:160
id:control2
text: qsTr("Button")
padding:0
//背景重绘
background:Rectangle{
anchors.fill: parent
color: "black"
}
contentItem: Rectangle {
//默认白色
color: "transparent"
Text {
id: txt
text: control.text
}
Image {
id: img
source: "/test.jpg"
width: 50
height: 50
anchors.right: parent.right
}
}
}
}