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

    xiaoxiao2022-07-04  174

    目录

     

     

    基本概念

    博主例子

    源码打包下载


     

    基本概念

    这里我只是把读到的东西做成一个小笔记,本来不想做的,因为太简单,但是在自己写例子的时候,发现这个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

    最新回复(0)