[Solved]QGraphicsItem
-
Dear All:
I am trying to create an application that perform scientifics graphics and I have a question. In all the tutorial I listen that the QGraphicsItem coordinates system is a local coordinate system that is not in pixel coordinates. In my application I need to define a QGraphicsItem coordinate system that match the pixel coordinates system.
This mean that if my QGraphicsItem has a size [30 60] I want to draw from 0 to 29 and 0 69 thinking that this are pixel in the screen.
Best and thanks in advance
Ernesto -
Well, if you don't zoom the scene in or out with the QGraphicsView, then the default zoom level will have 1 unit = 1 pixel. For individual items, QGraphicsItem::ItemIgnoresTransformations will probably do what you want.
Though, generally speaking you want to avoid counting pixels whenever possible. It can make it hard to move an application between different screens. (And in the case of things like retina displays, you need to deal with either very small pixels or "virtual" pixels and the definition of a pixel gets a bit vague.)
-
Hey,
Transformations
The transformation matrix tranforms the scene into view coordinates. Using the default transformation, provided by the identity matrix,one pixel in the view represents one unit in the scene: matrix 1:1
(e.g., a 10x10 rectangular item is drawn using 10x10 pixels in the view).If a 2x2 scaling matrix is applied, the scene will be drawn in 1:2
(e.g., a 10x10 rectangular item is then drawn using 20x20 pixels in the view).So: 1pixel in the view == 1 pixel in the scene if scaling matrix is 1:1
Coordinates
QGraphicsView by default centers coordinate 0x0 in the center of the view. This means that if you draw a QGraphicsItem to the QGraphicsScene (with x=0, y=0) your item is centred..by calling
@void QGraphicsView::setAlignment(Qt::AlignLeft | Qt::AlignTop)@Your item will be rendered in the top-left corner...
Info
You could compare
a QGraphicsScene like a (tree) model
a QGraphicsView like a (tree) view
a QGraphicsItem like your (model) records