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 file a some element in ListView?
QtWS25 Last Chance

How to file a some element in ListView?

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 1.2k 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.
  • T Offline
    T Offline
    Trikrista
    wrote on last edited by
    #1

    I have 10 item in ListView.
    I want in fifth item change color or call function
    How can I do it?

    I'm sorry for my bad English

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Are you using ListModel ? If so, then you can get the particulat Item using "get":http://doc.qt.io/qt-5/qml-qtqml-models-listmodel.html#get-method and then access its properties.

      157

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Trikrista
        wrote on last edited by
        #3

        But in model I can not call the function

        I'm sorry for my bad English

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Right. To change something like color you can use that way and to call a function you will need to that in delegate.
          @
          function getColor(index) {
          return "red"
          }

          delegate: Rectangle {
          color: getColor(index)
          }
          @

          157

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Trikrista
            wrote on last edited by
            #5

            I have item:
            @
            delegate: Rectangle {
            //---
            function changedColor(c) {
            }
            //---
            }
            @

            How I can call function changedColor(c) if I know index item?

            I'm sorry for my bad English

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              Maybe like this:
              @
              listview.currentIndex=1 // 1 is index which you know, listview = id of ListView
              console.log(listview.currentItem.changedColor())
              @

              157

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Trikrista
                wrote on last edited by
                #7

                Yes, this is it. Thank you

                I'm sorry for my bad English

                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