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

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

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值