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. QML combo box
Qt 6.11 is out! See what's new in the release blog

QML combo box

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 2.9k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    Belluri Uthej Reddy
    wrote on last edited by
    #1

    Hello,
    I have a list of elements in combo box. I want the combo box to do some action whenever I select anyone of the listed elements accordingly.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stcorp
      wrote on last edited by
      #2

      Something like this?

      ComboBox
      {
          model: ["One", "Two", "Three", "Four"]
          onActivated: console.log("I clicked item with index " + index + " which has label " + model[index])
      }
      
      1 Reply Last reply
      0
      • B Offline
        B Offline
        Belluri Uthej Reddy
        wrote on last edited by
        #3

        @stcorp
        Yes, Similar to the code which you provided. The checkbox should open another page when selected anyone in the list. When i use the code it throws an error as, "CANNOT RETRIEVE DEBUGGING OUTPUT" .

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stcorp
          wrote on last edited by
          #4

          It depends on how different you want each page for each user to be, but here is an example of how you could do it using a stackview.
          main.qml

          import QtQuick 2.7
          import QtQuick.Controls 2.0
          
          ApplicationWindow {
              visible: true
              width: 500
              height: 500
          
              StackView
              {
                  id: stackview
                  initialItem: Pane {
                      ComboBox
                      {
                          model: ["Anne", "Bob", "Charlie", "Dianne"]
                          onActivated: stackview.push("qrc:/window.qml", {"name": model[index]})
                      }
                  }
              }
          }
          

          window.qml

          import QtQuick 2.7
          import QtQuick.Controls 2.0
          
          Pane {
              property string name
              Column
              {
                  Button
                  {
                      text: "Close"
                      onClicked: stackview.pop()
                  }
                  Label
                  {
                      text: "This is an opened window for " + name
                  }
              }
          }
          

          Basically you have the homepage (initialItem) of the stackview, which displays the combobox. Then, whenever one of the names in the combobox is selected, it opens a new page from window.qml, with the property "name" being set to the selected name of the combobox.

          1 Reply Last reply
          1
          • B Offline
            B Offline
            Belluri Uthej Reddy
            wrote on last edited by
            #5

            Tanq Bro it worked perfect

            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