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] QML: QListView / QListModel force repainting listview / delegates
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QML: QListView / QListModel force repainting listview / delegates

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

    Hi,

    i have a simple ListModel and ListView which displays the data.

    The ListView has its own delegate which paints something on a Canvas.

    I have a function declared from which i want to trigger a repaint of the listview (the delegates which paint on a canvas).
    But nothing seems to trigger repainting the delegate. (onPaint from the canvas of the delegate is never called again).
    i Tryed model.revert()
    and listView.update...
    Nothing triggers repainting ...

    Any ideas?

    Greetings,
    Nando

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nando76
      wrote on last edited by
      #2

      Hi,

      i solved it by setting the model to 0 and then set it again.

      @
      menueListView.model = 0;
      menueListView.model = menueModel
      @

      It works but i think it is not the best solution. Any ideas?

      Greetings

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dasRicardo
        wrote on last edited by
        #3

        I mean the ListView only update it self if needed like the model data has changed. What you did is reset the model so the list must be repaint it self and also the delegates. What's your reason to force an update because the model data are fix right? Animated delegates?

        **Sorry for my english :)

        PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nando76
          wrote on last edited by
          #4

          Hi,
          i use this to realize a drop in menue.

          because i paint the delegates by myself i must trigger somehow the repaint operation after selection changes.
          if i click on a listview row i save the index and closes the menue....(and load the stuff for the selected row.)

          later when repopening the menue the menue must be painted with the new index selected...
          so i must somehow trigger the list view to repaint...

          Greetings

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dasRicardo
            wrote on last edited by
            #5

            Hmmm, but you don't need to repaint the whole listview you only need to repaint the canvas of the actual selected and the old selected item so maybe something like this can work:

            @
            ListView {
            id: list
            model: model
            anchors.fill: parent
            delegate: Canvas {
            anchors.left: parent.left
            anchors.right: parent.right
            height: 30
            onPaint: {
            var ctx = getContext("2d")
            ctx.fillStyle = 'green'
            if (list.currentIndex == index) {
            ctx.fillStyle = 'red'
            }
            ctx.fillRect(0, 0, this.width, this.height)
            }
            MouseArea {
            anchors.fill: parent
            onClicked: {
            if (list.currentIndex != -1) {
            list.currentItem.requestPaint()
            }
            list.currentIndex = index
            list.currentItem.requestPaint()
            }
            }
            }
            }
            @

            It's totaly dirty and an example but i hope i have understand what you want.

            **Sorry for my english :)

            PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dasRicardo
              wrote on last edited by
              #6

              Please add solved to your thread title

              **Sorry for my english :)

              PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

              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