Qt文档阅读笔记-RadioButton的基本使用

583 篇文章 127 订阅
35 篇文章 4 订阅

目录

 

 

基本概念

博主例子

源码打包下载


 

基本概念

这里我只是把读到的东西做成一个小笔记,本来不想做的,因为太简单,但是在自己写例子的时候,发现这个RaidoButton只要放到一起,就会成为一组,根本不需要使用ButtonGroup这些去做;下面来看看详细的代码。

 

博主例子

程序运行截图如下:

程序结构如下:

源码如下:

main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}

mian.qml

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Row{

        anchors.centerIn: parent

        ColumnLayout{

            RadioButton{
                checked: true
                text: "单选一"
            }

            RadioButton{

                checked: false
                text: "chose 1"
            }

            RadioButton{

                text: "chose 2"
            }
        }

        Column{

            id: column

            RadioButton{
                checked: true
                text: "one"
            }

            RadioButton{
                text: "two"
            }

            RadioButton{
                text: "three"
            }
        }

        ButtonGroup { id: radioGroup }

        Column {
            Label {
                text: qsTr("Radio:")
            }

            RadioButton {
                checked: true
                text: qsTr("DAB")
                ButtonGroup.group: radioGroup
            }

            RadioButton {
                text: qsTr("FM")
                ButtonGroup.group: radioGroup
            }

            RadioButton {
                text: qsTr("AM")
                ButtonGroup.group: radioGroup
            }
        }

    }

    Rectangle{

        RadioButton{
            text: "value1"
            y:0
        }

        RadioButton{
            text: "value2"
            y:20
        }

        RadioButton{
            text: "value3"
            y:40
        }
    }
}

 

源码打包下载

下载地址:

https://github.com/fengfanchen/Qt/tree/master/RadioButtonQML

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT1995

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值