Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Update listview model from delegate paint event
Qt 6.11 is out! See what's new in the release blog

Update listview model from delegate paint event

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.5k Views 2 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.
  • R Offline
    R Offline
    Rory_1
    wrote on last edited by
    #1

    I have a QListView where I custom draw the iconview using a delegate. I need to save a QRect containing the coordinates of part of an iconview item that can be used later to translate coordinates from a mouse click event on the thumbnail. I am having difficulties overcoming the const status.

    Here is a code snippet from the delegate:

    void ThumbViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                               const QModelIndex &index) const
    {
        // define iconRect coordinates
    
        // save iconRect to model
        index.model()->setData(index, iconRect, Qt::UserRole+5);
    
        // this generates error
        // qt cannot convert 'this' pointer from 'const QAbstractItemModel' to 'QAbstractItemModel &'
    }
    

    How do I update the model?

    Thanks in advance.
    Rory

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The paint event is not the place to do it at all, you should rather take a look at the mouse events related methods of QListView.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        The paint event is not the place to do it at all, you should rather take a look at the mouse events related methods of QListView.

        R Offline
        R Offline
        Rory_1
        wrote on last edited by Rory_1
        #3

        @SGaist

        Thanks. I would like to do it that way, but the paint event is the only place where the interior geometry of the iconview is defined. I think I have solved the problem with a signal/slot.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          QAbstractItemView::visualRect should give you that information.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply
          0
          • SGaistS SGaist

            You're welcome !

            QAbstractItemView::visualRect should give you that information.

            R Offline
            R Offline
            Rory_1
            wrote on last edited by Rory_1
            #5

            @SGaist

            No, it does not I am afraid. In my delegate I want the location of the icon, which I size and place within the visualRect. The visualRect only gives the outer dimensions.

            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