【Qt Quick】——去除窗口边框并自定义功能按钮
程序员文章站
2024-01-05 17:05:40
...
效果
代码
import QtQuick 2.0
import QtQuick.Controls 2.5
import QtQuick.Controls.Styles 1.4
Item {
id:i_BasicFunc
width: 90
height: 30
anchors.top: parent.top
anchors.right: parent.right
property var btn_BGColor: "#00000000"
property var text_Color: "white"
property bool b_IsTheZoom: false
//行的背景大小及颜色 方便查看行的区域
Rectangle{
id:i_Rec
anchors.fill: parent
color: "#00000000"
}
Row{
anchors.fill: parent
//最小化按钮
Button{
id:minBtn
width: parent.height
height: parent.height
Text{
text: "-"
color: text_Color
anchors.centerIn: parent
font.bold: true
font.pointSize: 14
}
background: Rectangle{
//当鼠标移入移出以及按下抬起时,背景颜色发生相应的改变
color: parent.hovered?(parent.pressed?"#b9b9b9":"#a0a0a0"):btn_BGColor
}
onClicked: {
//主窗口id+showMinimized() 最小化窗口
main_Window.showMinimized()
}
}
//最大化及正常显示按钮
Button{
id:maxBtn
width: parent.height
height: parent.height
Text{
text: "❐"
color: text_Color
anchors.centerIn: parent
font.bold: true
font.pointSize: 10
}
background: Rectangle{
color: parent.hovered?(parent.pressed?"#b9b9b9":"#a0a0a0"):btn_BGColor
}
onClicked: {
//加入bool变量判断当前窗口处于什么状态
if(!b_IsTheZoom){
b_IsTheZoom = true
main_Window.showMaximized()//最大显示
}else{
b_IsTheZoom = false
main_Window.showNormal()//正常显示
}
}
}
//退出按钮
Button{
id:closeBtn
width: parent.height
height: parent.height
Text{
text: "×"
color: text_Color
anchors.centerIn: parent
font.bold: true
font.pointSize: 12
}
background: Rectangle{
color: parent.hovered?(parent.pressed?"#b9b9b9":"#a0a0a0"):btn_BGColor
}
onClicked: {
Qt.quit()//退出
}
}
}
}