PDA

View Full Version : QGraphicsScene and its virtual drawBackground()/drawForeground() functions



keshav2010
26th March 2018, 16:52
Hello, I'm making a very small 2D animation software which basically allows the user to import images from pc and then render them on a specific location.
I'm using Qt's Graphics View Framework, the QGraphicsView is being used for displaying each frame of animation.
The frame itself inherits QGraphicsScene, now this frame class also contains a list of objects to render.

Now, I have multiple frames, which are being displayed on QGraphicsView, but the problem is my frame's drawBackground() or drawForeground() functions which I implemented aren't being called automatically unlike QGraphicsView's drawBackground() method.

Can you please help me what I'm doing wrong, till I get some concrete solution, I'm following this approach
Inside of my QGraphicsView's drawForeground() method, in executing this statement so as to update my frame repeatedly

scene()->render(painter, sceneRect(), sceneRect() );
this is working but I just don't understand why I need to call render() and why not QGraphicsScene::drawForeground() is not being called automatically.

d_stranz
27th March 2018, 21:59
Have you defined the overridden functions with exactly the same signatures as the virtual functions in QGraphicsScene? Are you drawing in scene coordinates as the documentation states? Have you run this in the debugger and confirmed that the functions are not being called? And it probably isn't relevant, but have you included the Q_OBJECT macro in your derived class definition?