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. ComboBox problem with using model(int) and delegate(ItemDelegate)

ComboBox problem with using model(int) and delegate(ItemDelegate)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 560 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.
  • K Offline
    K Offline
    kingsta
    wrote on last edited by
    #1

    Hi

    I have a problem with ComboBox. I have a C++ class that is name "program". I send some data from C++ to Qml. The data size in ComboBox can changes so I prefer use

    model: program.kategoriSayisi  //returns int value to ComboBox model. For example 9.
    

    I send values from C++ to Qml ComboBox with this code.

    text: program.kategoriAdi[index] //returns QVariantList value. I get values with index.
    

    Problems:

    • In the first openning tha qml page, I cant see values. I see empty value. But I click the ComboBox, I can see values in dropdown list.
    • When I select the value in dropdown list, I can't see the selected value. I see empty value.

    Where is my mistake?

    The code

    ComboBox {
        id: katgKutusu
        anchors.left: parent.left
        anchors.leftMargin: dp(2)
        anchors.top: eklenecekKatgYazisi.bottom
        anchors.topMargin: dp(2)
        width: parent.width*0.7
    
        textRole: "text"
    
        down: true
        model: program.kategoriSayisi // program.kategoriSayisi returns int value to ComboBox model. For example 9.
        delegate: ItemDelegate {
            id: katgObjeleri
            contentItem: Text {
                text: program.kategoriAdi[index] //program.kategoriAdi returns QVariantList value. I get values with index.
                font.pixelSize: dp(4)
                elide: Text.ElideRight
                verticalAlignment: Text.AlignVCenter
            }
    
            onClicked: {
                console.log("clicked:", program.kategoriAdi[index]) //When I click the some object in combobox, I can see the selected name
                console.log("index:", index)
                katgKutusu.currentIndex = index           //Is it wrong?
            }
        }
        currentIndex: 0 //I want to show first value in combobox
    
          onAccepted: {
              if (find(editText) === -1)
                  currentIndex = find(textAt(index))
    
              console.log("onAccepted") //never called!
              console.log("currentIndex: ", currentIndex) //never called!
          }
    }
    
    1 Reply Last reply
    0
    • K Offline
      K Offline
      kingsta
      wrote on last edited by
      #2

      Hello guys

      After a few try, I found the solution. I hope it helps people.

      ComboBox {
                  id: katgKutusu
                  anchors.horizontalCenter: parent.horizontalCenter
                  anchors.verticalCenter: parent.verticalCenter
                  width: parent.width*0.5
      
                  textRole: "text"            
      
                  signal katgSecildi(var sira) //send index value (sira) to outside of ItemDelegate
      
                  down: true
                  model: program.kategoriSayisi
                  delegate: ItemDelegate {
                      id: katgObjeleri
                      property alias seciliYazi: yazi.text
                      contentItem: Text {
                          id: yazi
                          text: program.kategoriAdi[index]
                          font.pixelSize: dp(3.5)
                          font.family: yazikarakteri1
                          color: tema.onplanRenk
                          elide: Text.ElideRight
                          verticalAlignment: Text.AlignVCenter
                      }
                      onClicked: {
                          katgKutusu.katgSecildi(index) //send index value to outside of ItemDelegate
                      }
                  }
                  onKatgSecildi: displayText = program.kategoriAdi[sira]  //assign index value of selected value to displayText'
                  displayText: program.kategoriAdi[0] //in first run, it shows first value of array
              }
              }
      
      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