QGraphicsScene in paintEvent ?
I can create and display a graphics scene, in main(), like this -
Code:
Button *button;
Button *button2;
scene.addPixmap(bg);
button = new Button();
button2 = new Button();
scene.addItem(button);
scene.addItem(button2);
view.setScene(&scene);
view.show();
How would I alter the code to put it in a paintEvent function ? Thanks in advance. :confused:
Re: QGraphicsScene in paintEvent ?
paintEvent() is an event handler, which is called by Qt when a widget needs to paint it self (QPaintEvent).
You do not call event handlers your self, they get called by the event loop.
If you want a widget to have a custom painting, you have to re implement its paintEvent(), but leave the calling to the event loop.
Therefore, your question is "wrong", since paintEvent() never comes by its self, its a member method, which you do not call, just re implement.
Re: QGraphicsScene in paintEvent ?
I realise that paintEvent() is not directly called and has to be re-implemented - I was wondering if someone could give me example code showing how my example use of a graphics scene construction in main() would look in paintEvent() ?
Re: QGraphicsScene in paintEvent ?
Constructing a graphics scene in a paint event doesn't make any sense. Paint event should only contain code for redrawing the widget it is part of.
Re: QGraphicsScene in paintEvent ?
Quote:
how my example use of a graphics scene construction in main() would look in paintEvent()
this sentence has not meaning... or I fail to to extract any meaning from it.
Maybe if you explain what it is you want to do, we might help you to get in the right direction.
Re: QGraphicsScene in paintEvent ?
I also am a little bit confused with what you're trying to do....Are you trying to have a scene embedded in a widget that is recreated every single time the paintevent for the parent widget is called? If that is the case, I believe that in the way qgraphicsscene is currently implemented, all events sent to a parent object are automatically sent to the scene as well, so you shouldn't have to tie the two together. If you are, however, trying to create a brand-new graphics scene every time the paintevent event is called in the eventloop is would urge you to rethink your implementation.