GraphicsView/Scene not refreshing



  • 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.



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



  • That seems to do the trick, thanks!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.