2

I wish to draw a period or dot or point in GraphicsView that:

  • has an arbitrary size, which works like the radius of a circle,

  • is affected by scaling transformations in that its position is changed according to the current scale,

  • but its arbitrary size is NOT affected by scaling.

The problem I'm specifically tackling is depicting celestial bodies in a solar system visualizer. I want to make things with the proper distances from each other, but space is unimaginably empty - trying to depict an Earth-sized object with a proper radius would make it very hard for the viewer to actually see anything if said user zoomed out enough to see other planets. Therefore, I would like to mark the locations with dots that don't scale in diameter, while everything else (like orbital paths, distances) scales.

I have tried to use ItemIgnoresTranformations, but that makes the object ignore both the size changes and the location changes when scale is altered. I want the object to be noticeable regardless of scale, but at the same time for it to be in its proper place.

Alternative solutions welcome.

EDIT1:

The new code looks like so:

ellipse2 = scene->addEllipse(0, 0, body.radius,body.radius,blackPen,greenBrush); 
ellipse2->setFlag(QGraphicsItem::ItemIgnoresTransformations);
ellipse2->setPos(system.starX+body.getX(date2days(game.date))-body.radius/2.0,
                 system.starY+body.getY(date2days(game.date))-body.radius/2.0);

Previously, the position was simply put in the the place of the 0s in the addElipse() call. However, there is a problem - the planets' movements don't quite match the plotted orbital paths (I am currently simplifying to perfect circles with constant angular speed, rather than elliptical paths with variable angular speed). The actual paths seem to be shifted by some unknown (but scale-dependent) amount towards the top-left.

Here is how it looks unzoomed:
Before
And here is how it looks zoomed:
After

This problem does not occur if the item is affected by transformations. What gives?

Abu Dhabi
  • 311
  • 4
  • 13
  • 1
    `QGraphicsItem::ItemIgnoresTransformations` should do exactly what you want. The problem might be how you add your items in the scene. See [this](http://stackoverflow.com/questions/20125130/fixed-size-qgraphicsitems-in-multiple-views) question. – thuga Apr 07 '14 at 06:23
  • Thanks! This helped, but the result is still subtly wrong. I have edited with an explanation. It strikes me that the problem may be the body.radius - but how do I determine the current scale to scale it? – Abu Dhabi Apr 07 '14 at 10:30
  • Found the problem and posted solution. – Abu Dhabi Apr 07 '14 at 11:18

1 Answers1

2

Found the problem. I needed to adjust for planetary radius in the rect, not the pos.

The correct code for this looks like:

ellipse2 = scene->addEllipse(-body.radius/2,
                             -body.radius/2,
                             body.radius,body.radius,blackPen,greenBrush);
ellipse2->setFlag(QGraphicsItem::ItemIgnoresTransformations);
ellipse2->setPos(system.starX+body.getX(date2days(game.date)),
                 system.starY+body.getY(date2days(game.date)));
Abu Dhabi
  • 311
  • 4
  • 13