Forums

OverviewFelgo 2 Support (Qt 5) › How to create a set of checkboxes that only one of them can be checked ?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #18954

    Yusuf Umut Piynar

    Hello I got 5 checkboxes

    AppCheckBox{

         id : optionA
         text:"A)"
         width: parent.width / 5
    
    
         }
     AppCheckBox{
         id: optionB
         width: parent.width / 5
       text:"B)"
     }
     AppCheckBox{
         id : optionC
         width: parent.width / 5
       text:"C)"
     }
     AppCheckBox{
         id : optionD
         width: parent.width / 5
       text:"D)"
     }
     AppCheckBox{
         id : optionE
         width: parent.width / 5
       text:"E)"
     }
    }

    I want user to be able to only check one of them at once.How do I can do that ?

    #18955

    Javier
    #18959

    Yusuf Umut Piynar

    I achieved my goal with this script but its the worst performance script that ever written, btw I can change it to radiobuttons later..

    if (optionA.checked == true){

            optionB.checked = false
            optionC.checked = false
            optionD.checked = false
            optionE.checked = false
        }
    
    
        if (optionB.checked == true){
            optionA.checked = false
            optionC.checked = false
            optionD.checked = false
            optionE.checked = false
        }
        if (optionC.checked == true){
            optionA.checked = false
            optionB.checked = false
            optionD.checked = false
            optionE.checked = false
        }
        if (optionD.checked == true){
            optionA.checked = false
            optionB.checked = false
            optionC.checked = false
            optionE.checked = false
        }
        if (optionE.checked == true){
            optionA.checked = false
            optionB.checked = false
            optionC.checked = false
            optionD.checked = false
        }
    #18964

    Alex
    Felgo Team

    Hi,

    you can use the exclusiveGroup property of the AppCheckBox, which is inherited from CheckBox:

    import Felgo 3.0
    import QtQuick 2.9
    import QtQuick.Controls 1.4
    
    App {
    
      NavigationStack {
      
        Page {
          title: "ExclusiveGroup"
          
          ExclusiveGroup {
            id: myGroup
          }
          
          Column { 
            anchors.centerIn: parent
            spacing: dp(20)
            
            AppCheckBox {
              text: "CB1"
              exclusiveGroup: myGroup
            } 
            AppCheckBox {
              text: "CB2"
              exclusiveGroup: myGroup
            }
          }
        }
      }
    }

    Note: To post code, please use the “Code” button in the editor.

    Cheers,
    Alex

Viewing 4 posts - 1 through 4 (of 4 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support