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. ListView And The Items
Qt 6.11 is out! See what's new in the release blog

ListView And The Items

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 2.4k 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.
  • S Offline
    S Offline
    shahriar25
    wrote on last edited by
    #1

    Hi, I have a problem with ListView and getting and setting the view's item's property, here is the code:

    import QtQuick 2.5

    Item {
    id: root
    clip: true

    property color mainColor
    property color textColor
    property color greyTextColor
    property color specialMainColor
    property color specialTextColor
    property color invertMainColor
    property color invertTextColor
    property color pressedColor
    property color hoverColor
    
    property string playIcon
    
    property int activeRow: MLoader.activeQueueRow
    
    ListView{
        id: listView
    
        anchors.fill: parent
    
        model: MLoader.queueRowCount
        delegate: QueueDelegate{
            mainColor: root.mainColor
            textColor: root.textColor
            invertMainColor: root.invertMainColor
            invertTextColor: root.invertTextColor
            greyTextColor: root.greyTextColor
            pressedColor: root.pressedColor
            hoverColor: root.hoverColor
    
            playIcon: root.playIcon
    
            width: root.width
            height: textHeight + root.height/12
    
            delegateIndex: index
            delegatePlayState: false
    
            title: MLoader.queueValue(index,0)
            artist: MLoader.queueValue(index,1)
            artwotk: "file://" + MLoader.queueValue(index,3)
        }
    }
    
    onActiveRowChanged: {
        listView.model.get(activeRow).delegatePlayState = true
    }
    

    }

    I want to change an item's property when a signal is activated but the code doesn't work. what should I do?

    p3c0P M 2 Replies Last reply
    1
    • S shahriar25

      Hi, I have a problem with ListView and getting and setting the view's item's property, here is the code:

      import QtQuick 2.5

      Item {
      id: root
      clip: true

      property color mainColor
      property color textColor
      property color greyTextColor
      property color specialMainColor
      property color specialTextColor
      property color invertMainColor
      property color invertTextColor
      property color pressedColor
      property color hoverColor
      
      property string playIcon
      
      property int activeRow: MLoader.activeQueueRow
      
      ListView{
          id: listView
      
          anchors.fill: parent
      
          model: MLoader.queueRowCount
          delegate: QueueDelegate{
              mainColor: root.mainColor
              textColor: root.textColor
              invertMainColor: root.invertMainColor
              invertTextColor: root.invertTextColor
              greyTextColor: root.greyTextColor
              pressedColor: root.pressedColor
              hoverColor: root.hoverColor
      
              playIcon: root.playIcon
      
              width: root.width
              height: textHeight + root.height/12
      
              delegateIndex: index
              delegatePlayState: false
      
              title: MLoader.queueValue(index,0)
              artist: MLoader.queueValue(index,1)
              artwotk: "file://" + MLoader.queueValue(index,3)
          }
      }
      
      onActiveRowChanged: {
          listView.model.get(activeRow).delegatePlayState = true
      }
      

      }

      I want to change an item's property when a signal is activated but the code doesn't work. what should I do?

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @shahriar25 Does the model have delegatePlayState ?

      157

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shahriar25
        wrote on last edited by
        #3

        Hi @p3c0
        the model is a cpp function (Q_PROPERTY) that returns an integer

        p3c0P 1 Reply Last reply
        0
        • S shahriar25

          Hi, I have a problem with ListView and getting and setting the view's item's property, here is the code:

          import QtQuick 2.5

          Item {
          id: root
          clip: true

          property color mainColor
          property color textColor
          property color greyTextColor
          property color specialMainColor
          property color specialTextColor
          property color invertMainColor
          property color invertTextColor
          property color pressedColor
          property color hoverColor
          
          property string playIcon
          
          property int activeRow: MLoader.activeQueueRow
          
          ListView{
              id: listView
          
              anchors.fill: parent
          
              model: MLoader.queueRowCount
              delegate: QueueDelegate{
                  mainColor: root.mainColor
                  textColor: root.textColor
                  invertMainColor: root.invertMainColor
                  invertTextColor: root.invertTextColor
                  greyTextColor: root.greyTextColor
                  pressedColor: root.pressedColor
                  hoverColor: root.hoverColor
          
                  playIcon: root.playIcon
          
                  width: root.width
                  height: textHeight + root.height/12
          
                  delegateIndex: index
                  delegatePlayState: false
          
                  title: MLoader.queueValue(index,0)
                  artist: MLoader.queueValue(index,1)
                  artwotk: "file://" + MLoader.queueValue(index,3)
              }
          }
          
          onActiveRowChanged: {
              listView.model.get(activeRow).delegatePlayState = true
          }
          

          }

          I want to change an item's property when a signal is activated but the code doesn't work. what should I do?

          M Offline
          M Offline
          medyakovvit
          wrote on last edited by
          #4

          @shahriar25
          If you want to change property of Listview currentItem, then

          onCurrentItemChanged(){
              currentItem.delegatePlayState = true;
          }
          
          M 1 Reply Last reply
          0
          • S shahriar25

            Hi @p3c0
            the model is a cpp function (Q_PROPERTY) that returns an integer

            p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            @shahriar25
            To update a delegate using a model you will need to bind the properties defined in the model with the delegate. Then you need to modify that particular property in the model and notify the delegate about the changes using dataChanged.

            But in your case you don't have QAbstractItemModel based model so above solution wont work. @medyakovvit's answer should be sufficient.

            157

            1 Reply Last reply
            1
            • M medyakovvit

              @shahriar25
              If you want to change property of Listview currentItem, then

              onCurrentItemChanged(){
                  currentItem.delegatePlayState = true;
              }
              
              M Offline
              M Offline
              medyakovvit
              wrote on last edited by
              #6

              @medyakovvit said:

              @shahriar25
              If you want to change property of Listview currentItem, then

              onCurrentItemChanged(){
                  currentItem.delegatePlayState = true;
              }
              

              Or if you want to set currentItem.delegatePlayState = true and set previous currentItem.delegatePlayState = false, then you can try to write in Listview delegate:

              delegate: QueueDelegate{
                 // bla bla bla
                 delegatePlayState: Listview.isCurrentItem
                 // bla bla bla
              }
              
              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