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. Make a conditional rule between combobox value and button.
Forum Updated to NodeBB v4.3 + New Features

Make a conditional rule between combobox value and button.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 889 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.
  • amir.sanaatA Offline
    amir.sanaatA Offline
    amir.sanaat
    wrote on last edited by
    #1

    Hi, my friends.
    In my application, I want when the user selects the A or B from combobox and click on the NEXT button the application open different page (Page1.qml for A and Page2.qml for B).

    The below code doesn't work, and I don't have any idea.As I'm not a qt expert, any help would be a great help.

    Thank you.

    
    import QtQuick 2.6
    import QtQuick.Controls 2.2
    
    ScrollablePage {
        id: page
    
        Column {
            id: column
            spacing: 40
            width: parent.width
    
            Label {
                width: parent.width
                wrapMode: Label.Wrap
                horizontalAlignment: Qt.AlignHCenter
                text: "Select A or B"
            }
    
            ComboBox {
                model: ["B", "A"]
                anchors.horizontalCenter: parent.horizontalCenter
            }
    
    
            Button {
    
                id: button
                text: "NEXT"
                y:-300
    
                anchors.bottom: parent.bottom
                width: Math.max(button.implicitWidth, Math.min(button.implicitWidth * 2, pane.availableWidth / 3))
                onClicked: {
                    if(qsTr(ComboBox.currentText)==="A"){
                        stackView.push("qrc:/pages/Page1.qml")
                    }
                    else
                        stackView.push("qrc:/pages/Page2.qml")
                }
    
            }
        }
    }
    
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mammamia
      wrote on last edited by Mammamia
      #2

      You are using the object wrong because you don't have an id for it.

      set an id for combobox

      ComboBox {
                  id: selectionCombo
                  model: ["B", "A"]
                  anchors.horizontalCenter: parent.horizontalCenter
              }
      

      and use the id to check the condition

      onClicked: {
                      if(qsTr(selectionCombo.currentText)==="A"){
                          stackView.push("qrc:/pages/Page1.qml")
                      }
                      else
                          stackView.push("qrc:/pages/Page2.qml")
                  }
      

      Note: I didn't compile and check the functionality. Hope this will solve your issue.

      amir.sanaatA 1 Reply Last reply
      0
      • M Mammamia

        You are using the object wrong because you don't have an id for it.

        set an id for combobox

        ComboBox {
                    id: selectionCombo
                    model: ["B", "A"]
                    anchors.horizontalCenter: parent.horizontalCenter
                }
        

        and use the id to check the condition

        onClicked: {
                        if(qsTr(selectionCombo.currentText)==="A"){
                            stackView.push("qrc:/pages/Page1.qml")
                        }
                        else
                            stackView.push("qrc:/pages/Page2.qml")
                    }
        

        Note: I didn't compile and check the functionality. Hope this will solve your issue.

        amir.sanaatA Offline
        amir.sanaatA Offline
        amir.sanaat
        wrote on last edited by
        #3

        @Mammamia thank you my friend. it works.

        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