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. Item paint() on every re-call to addItem() to QGraphicsScene
QtWS25 Last Chance

Item paint() on every re-call to addItem() to QGraphicsScene

Scheduled Pinned Locked Moved General and Desktop
3 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.
  • S Offline
    S Offline
    sairajesh
    wrote on last edited by
    #1

    Hi,

    In my code, I holding references of all items that are added to scene in a QList, on some event I parse the QList and call scene->addItem(). With this call, item's paint() is getting invoked which is perfect. Now, user clicks "redraw" button on selected items to redraw all selected items at other selected position, on which I do removeItem() for selected items and again do addItem() at the user specified position (mouseclick). But in this case, I see paint() of item is not getting called. Paint() is getting invoked for any new item I create but not for items that were removed and added again.

    Note: I'm not unref the item when doing removeItem(). I want that item reference and I just update item co-ordinates as per user mouse click and wil try to redraw the item at specified position. So, I use setPosition() of item and call addItem() again. Item is getting moved to new position but paint() is not getting called. I cant use scene->clear() because it appears to unref the item even.

    My aim is to remove it from scene and re-add it at given position with paint() called. Currently, item is getting added at given position but its paint() is not getting invoked 2nd time.

    Please help me.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      I don't 100% understand your use case, but normally, you wouldn't have to remove and re-add the item.

      If you just want to move it, call setPos.
      If you want to give it another parent, call setParent and then setPos to position it correctly in respect to it's new parent.
      If you need to check whether the item is already in the scene, use scene()

      One reason why paint might not be called is caching. Check the cacheMode() of the item.

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

        Thanks for the reply. My project involves drawing lines and nodes. And condition to be satisified is if line is open-ended, the ends shuld be marked by different color. If line is joined by other line it should be painted in other color. Hence, I need to have paint function called on every line draw so that I see if line is open-ended or not. But thanks anyways, cacheMode() worked!.

        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