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. GraphicsView/Scene not refreshing
Forum Updated to NodeBB v4.3 + New Features

GraphicsView/Scene not refreshing

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 958 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.
  • R Offline
    R Offline
    Raaap
    wrote on last edited by
    #1

    I'm using a QGraphicsView which holds a QGraphicsScene that in turn holds a number of objects of a class derived from QGraphicsRectItem. I've overwritten the paint function for it:
    @
    void paint(args etc){
    if(cell == nullptr)
    painter->fillRect(rect(), noConnection);
    else if(!cell->currentState)
    painter->fillRect(rect(), inactive);
    else
    painter->fillRect(rect(), active);

    painter->drawRect((rect()));
    

    }
    @

    It essentially draws a rectangle with a color decided by the state of the 'cell' object, which it has a pointer to. The only problem is, when I change that state(and then return to the event loop) it's not reflected by the graphics until I do something else. By else I mean pressing any button in the application, even if it doesn't touch on related code.

    I've tried various things like forcing the window to update, manually calling the process events function, forcing graphics view to repaint, etc. Nothing's having an effect, so I'm kinda at a loss. It's my first time using Qt so I could well be missing something obvious.

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

      Have you called QGraphicsItem::update(..) after you changed item state?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Raaap
        wrote on last edited by
        #3

        That seems to do the trick, thanks!

        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