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. How to set individual combo boxes currentindex?
Forum Updated to NodeBB v4.3 + New Features

How to set individual combo boxes currentindex?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.1k 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.
  • G Offline
    G Offline
    gnris
    wrote on 8 May 2014, 03:42 last edited by
    #1

    Hello,I have some question about set the combobox currentindex.
    I write some code like this
    @
    ListModel {id: author1} //data may append from other model

    TableView {
    model: author1
    TableViewColumn{
    role: “attribute”
    title: “attribute”
    width: 180
    delegate:Rectangle {
    ComboBox {
    id:combo
    model:author1
    textRole: “attribute”
    anchors.fill: parent
    Component.onCompleted: {
    var i
    for(i=0;i<combo.count;i++)
    combo.currentIndex=i
    }
    }
    }
    }
    @

    Can I control each combobox in Component.onCompleted?
    The code I wrote above can only set the last element to be currentindex.
    I want to set each combobox currentindex according to the order in Listmodel.
    i.e. the second combobox should set its currentindex to 1 (currentindex start from 0)

    Thanks!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gnris
      wrote on 11 May 2014, 12:45 last edited by
      #2

      OK..I got the answer.
      use
      @
      onCountChanged: {

      combo.currentIndex = combo.find(styleData.value);
      }
      @

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jens
        wrote on 11 May 2014, 12:49 last edited by
        #3

        The delegate is created per row so you do not want a loop in there.

        What you are looking for is probably styleData.row which will give you the current row index of the delegate. Another issue is that you should not really rely on "onCompleted" for items in tableview delegates since the created instance can get recycled multiple times.

        @
        ComboBox {
        id:combo
        model:author1
        textRole: "attribute"
        anchors.fill: parent
        currentIndex: styleData.row
        }
        @

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gnris
          wrote on 11 May 2014, 12:55 last edited by
          #4

          Thanks for your suggestion and reply!!

          1 Reply Last reply
          0

          1/4

          8 May 2014, 03:42

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved