PDA

View Full Version : QPainter and QGraphicsScene



lxman
15th October 2011, 13:27
Hello all,

I am trying to create an application to draw lines of force given several point charges. To do so, I have set up the following:

MainWindow with a QGraphicsView, to which I assign a QGraphicsScene.

I then have a QGraphicsEllipseItem derived class (Charge), of which I derive several instances and add them to the scene.

Each instance of the Charge class has a list of curved lines each defined as a list of QPointF's.

I use the paint() event to paint the objects along with their respective curved lines.

The issue I am running across is this:

The set of curved lines emerging from each Charge object are supposed to be different. When I draw them, however, they all display identically. In other words, each object ends up with the same curved line(s) drawn relative to that object. My calculations are correct. Each Charge object does have a different list of points for each of the curved lines.

The core of the problem, I think I have discovered, is the fact that each time paint() gets called on one of the Charge objects, whoever is doing the calling is passing the same QPainter object. It looks to me like if I try to draw one Charge object, then draw a separate object in another location, somehow the second object ends up being a carbon copy of the first, rather than being drawn with its own characteristics. Or vice-versa, I'm not sure which.

Anyway, does anybody have any suggestions on a better approach, or how to make this approach work, so that I can draw each of my custom objects independently?

totem
15th October 2011, 23:08
could you precise with problematic piece of code

Spitfire
17th October 2011, 16:43
The single painter seems correct, in the end you have only one scene on which you draw all your objects.