Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

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.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded