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. [solved] ListView: Change background image of selected item
QtWS25 Last Chance

[solved] ListView: Change background image of selected item

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

    Hi people!

    I have a listview where I put a background image for each item, but I can not do to change that image when the item is clicked / touched.

    Anyone have a how to explain to me how?

    code:

    @ ListView {
    id:listviewprin
    anchors.fill: telaprin
    clip: true
    model: animalsModel
    delegate: listDelegate
    focus: true
    Component {
    id: listDelegate
    Item {
    width: 480; height: 80

    //background image
    Image {
    id: imagem_fundo_listview
    width: telaprin.width
    height: 80
    source: "qrc:/imagens/imagens/list_item.png"
    Image {
    id: thumbail
    width: telaprin.width / 4
    height: 80
    source: pic
    }
    Text {
    id: dados
    text: " "+name
    font.bold: false
    font.pointSize: 20
    anchors.left: thumbail.right
    anchors.verticalCenter: parent.verticalCenter
    }
    }
    MouseArea {
    anchors.fill: parent
    onClicked: {
    selectedLinhaList = index;
    console.log("clicado "+selectedLinhaList);
    }
    }
    states: [
    State {
    name: "selected"
    when: (listviewprin.currentIndex==selectedLinhaList)
    // PropertyChanges {target: highlightBar; Image.y: listviewprin.currentItem.y }
    }
    ]
    }
    } //Component
    }//listview@

    Thank's.

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

      In your MouseArea's onClicked function set
      @ imagem_fundo_listview.source = "yournewimagepath" @

      157

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jeanrl
        wrote on last edited by
        #3

        Thanks, it worked, but if I click it all goes rather than selecting all deselect already selected.

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

          Ok. Can you explain it more clearly as to what is exactly happening ?

          157

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jeanrl
            wrote on last edited by
            #5

            No problem, your tip was extremely important and I solved the problem multiselect.

            Thank you again.

            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