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

来源:互联网 发布:怎样分享淘宝宝贝 编辑:程序博客网 时间:2024/05/16 17:13


在编写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();


原创粉丝点击