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. Problems setting ComboBox currentIndex
Qt 6.11 is out! See what's new in the release blog

Problems setting ComboBox currentIndex

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 734 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.
  • I Offline
    I Offline
    igor_stravinsky
    wrote on last edited by igor_stravinsky
    #1

    QuickControls 2 using Qt 5.11....

    I've got a comboBox, and I'm trying to change the model and current index for it using javascript on a property change:

    onMyPropertyChanged: {
                        
            if (MyProperty <100){
                 model= ["15"];
                  myComboBox.currentIndex = 0;
            }
           else {
                model=["15","27"];
                myComboBox.currentIndex = 1;
           }
    }
    

    I'm seeing the correct choices in the menu after the property change happens, but the menu looks blank, as if index -1 has been chosen. If I print the currentText for the comboBox, it reports the correct choice is selected, but it's not showing.

    Is there some sort of refresh that needs to happen in order to see the correct index showing?

    1 Reply Last reply
    0
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      @igor_stravinsky hi,

      you don't need to refresh, i just tested this and it works a expected

      Window {
          visible: true
          width: 640
          height: 480
          property bool tgl:false
      
          onTglChanged: {
              combo.model = ["1111","2222","3333"]
              combo.currentIndex=2;
          }
      
          ComboBox {
              id:combo
              editable: true
              model:["11","22","33"]
          }
      
          Button{
              anchors.centerIn: parent
              onClicked: tgl = !tgl
              text:"combo index : " + combo.currentIndex
          }
      }
      
      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