Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
flipping of items in the GraphicScene
I need to draw items in Cartesian co ordinates which (0,0) starts from bottom left , and X grows right side and y -grows upward.But qt draws the items in scene in reverse way.
what is the best way to flip the Y-axis.
Asperamanca last edited by
You can define the "origin point" of a QGraphicsItem through it's bounding rect:
Create your own class derived from QGraphicsItem. You need to overload paint and boundingRect methods.
The 0/0 position within the boundingRect you return is the origin for your item. To create an item that is 20 px wide and 10 px high, and has it's origin in the bottom right corner, return
QRectF(QPointF(-20.0, -10.0), QPointF())
Of course, all your painting within the item now has to happen within this rectangle, i.e. you have to draw on the negative side of the coordinate system.
Thanks for the reply.
I need to flip the objects in Scene coordinates not with in boundingrect.
for example I draw the item of 900x900 rectangle, now the (0,0 ) starts from top left and x grows right and y axis grows as downwards.
My requirement is to draw the Y -axis from left bottom to grow upwards. and X-axis grows right side.
ofmrew last edited by
@Jaisan Flipping when drawing on a widget you must first scale with x=1 and y=-1, then translate by an amount to move the top left corner down to the bottom left corner. You are flipping the entire scene. I have not tried it with GraphicsScene because it handles drawing.
You correct , as a permanent solution I would like to flip the entire scene co ordinate such that handling of objects with respect with will be easier.
If we flip or offset the object alone then we need to do this tedious operation on every object handling .
Like carrying a offset always in the co ordinates.
I think you can get it with
However, it might have side effets.
Thanks, it works as I expected.
But the side effect is , able to view RubberBand but no effect on completion.
What about texts ?
The link talks about it might affect texts but im not sure in what way :)
Yes text were mirrored and also Rubberband selection is not working
any other way to fix thisin scene
Text is fixed by Textitem->scale(-1,1) on paint() method.