Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. RadioButton in qml
Qt 6.11 is out! See what's new in the release blog

RadioButton in qml

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 763 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QtQmlLearner
    wrote on last edited by QtQmlLearner
    #1

    Hi,

    I am trying to create a RadioButton in qml as shown below:

    import QtQuick 2.12
    import QtQuick.Templates 2.12 as T
    import QtQuick.Controls 2.12
    import QtQuick.Controls.impl 2.12
    import QtQuick.Layouts 1.14
    import QtQuick.Controls.Styles 1.4
    
    
    T.RadioDelegate
    {
        RadioButton {
            id: r1
            checked: true
            text: qsTr("Option one")
        }
        RadioButton {
            id: r2
            text: qsTr("Option two")
            anchors.top: r1.bottom
        }
        RadioButton {
            id: r3
            text: qsTr("Option three")
            anchors.top: r2.bottom
        }
    }
    

    In this i am trying to change the background color of radio button can anyone suggest how to do that?

    B 1 Reply Last reply
    0
    • Q QtQmlLearner

      Hi,

      I am trying to create a RadioButton in qml as shown below:

      import QtQuick 2.12
      import QtQuick.Templates 2.12 as T
      import QtQuick.Controls 2.12
      import QtQuick.Controls.impl 2.12
      import QtQuick.Layouts 1.14
      import QtQuick.Controls.Styles 1.4
      
      
      T.RadioDelegate
      {
          RadioButton {
              id: r1
              checked: true
              text: qsTr("Option one")
          }
          RadioButton {
              id: r2
              text: qsTr("Option two")
              anchors.top: r1.bottom
          }
          RadioButton {
              id: r3
              text: qsTr("Option three")
              anchors.top: r2.bottom
          }
      }
      

      In this i am trying to change the background color of radio button can anyone suggest how to do that?

      B Offline
      B Offline
      Bob64
      wrote on last edited by
      #2

      @QtQmlLearner the Qt documentation has a section on customising controls, including RadioButton. The general idea is to create your own custom derived type and use that in place of the built-in type.

      https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-radiobutton

      Q 1 Reply Last reply
      1
      • B Bob64

        @QtQmlLearner the Qt documentation has a section on customising controls, including RadioButton. The general idea is to create your own custom derived type and use that in place of the built-in type.

        https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-radiobutton

        Q Offline
        Q Offline
        QtQmlLearner
        wrote on last edited by
        #3

        @Bob64 Thank you so much for the link.

        I just want to know what is the difference between RadioButton and RadioDelegate.
        If you have any idea can you suggest??

        1 Reply Last reply
        0
        • B Offline
          B Offline
          berni
          wrote on last edited by
          #4

          RadioButton is similar to RadioDelegate, except that it is typically not used in views (Listview, Gridview), but rather when there are only a few options, and often with the requirement that each button is uniquely identifiable.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved