Qt quick 按钮控件及其样式设置

xiaoxiao2021-02-28  146

在编写qml文档如果想要使用Button控件就必须在文件头部添加:import QtQuick.Controls 1.4

如果想要设置Button的样式则需要在文件头部添加:import QtQuick.Controls.Styles 1.4

import QtQuick 2.5 import QtQuick.Window 2.2 import QtQuick.Controls 1.4 import QtQuick.Controls.Styles 1.4 Window { visible: true width: 320 height: 400 color: "green" Button { id: openFile text: "打开" width: 100 height: 40 //anchors作为当前控件Button的锚点,可以表示控件的上下边的y左右边的x //Button左边边界的值为Window左边边界的值 anchors.left: parent.left //边界相隔距离从0变成了10,相当于Button向左平移了10 anchors.leftMargin: 10 anchors.top: parent.top anchors.topMargin: 10; } Button { id: quit text: "退出" width: 100 height: 40 anchors.right: parent.right anchors.rightMargin: 10 anchors.bottom: openFile.bottom style: ButtonStyle { //进行对Button的样式设置 background: Rectangle { //设置圆角 radius: 5; color: "red" } } //点击按钮则退出程序 onClicked: { Qt.quit() } } } //特别的,信号与槽在Qt Quick中的使用:如发出sendMsg信号,则响应的槽函数为onSendMsg();

 

 

转载请注明原文地址: https://www.6miu.com/read-31051.html

最新回复(0)