Qt-interest Archive, May 2008
GraphicsView and upside down coordinate system
Message 1 in thread
Hello,
In a mathematics oriented application I want my 2D coordinate system
with an x-axis oriented from left to right, and the y-axis from bottom
to top.
In the graphics view the x-coordinates are ok, the y-coordinates are not.
Is there an easy way to fix that, not only for output, but also for
input, that is for remapping mouse coordinates.
andreas
--
[ signature omitted ]
Message 2 in thread
Hi,
Andreas Fabri wrote:
>
> Hello,
>
> In a mathematics oriented application I want my 2D coordinate system
> with an x-axis oriented from left to right, and the y-axis from bottom
> to top.
>
>
> In the graphics view the x-coordinates are ok, the y-coordinates are not.
>
> Is there an easy way to fix that, not only for output, but also for
> input, that is for remapping mouse coordinates.
>
you can try this:
QMatrix m(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); // identity matrix with reversed Y-axis
QGraphicsView::setMatrix(m);
HTH
Albert
--
[ signature omitted ]
Message 3 in thread
On Tuesday 13 May 2008 16:18:35 Albert Zhykhar wrote:
> Hi,
>
> Andreas Fabri wrote:
> > Hello,
> >
> > In a mathematics oriented application I want my 2D coordinate system
> > with an x-axis oriented from left to right, and the y-axis from bottom
> > to top.
> >
> >
> > In the graphics view the x-coordinates are ok, the y-coordinates are not.
> >
> > Is there an easy way to fix that, not only for output, but also for
> > input, that is for remapping mouse coordinates.
>
> you can try this:
>
> QMatrix m(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); // identity matrix with reversed
> Y-axis QGraphicsView::setMatrix(m);
Would that not affect text as well resulting in it to be mirrored?
--
[ signature omitted ]
Message 4 in thread
Hi,
Kishore wrote:
> On Tuesday 13 May 2008 16:18:35 Albert Zhykhar wrote:
>> Hi,
>>
>> Andreas Fabri wrote:
>>> Hello,
>>>
>>> In a mathematics oriented application I want my 2D coordinate system
>>> with an x-axis oriented from left to right, and the y-axis from bottom
>>> to top.
>>>
>>>
>>> In the graphics view the x-coordinates are ok, the y-coordinates are not.
>>>
>>> Is there an easy way to fix that, not only for output, but also for
>>> input, that is for remapping mouse coordinates.
>> you can try this:
>>
>> QMatrix m(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); // identity matrix with reversed
>> Y-axis QGraphicsView::setMatrix(m);
>
> Would that not affect text as well resulting in it to be mirrored?
Yes. If there are graphics items which you want to appear the right way
up, a partial solution is to invert them as well. That way they get
double-inverted and are displayed the correct way up for the user. I
have used something similar to this.
Cheers,
Ian.
This email and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to whom they are addressed. If you are not the original recipient or the person responsible for delivering the email to the intended recipient, be advised that you have received this email in error, and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you received this email in error, please immediately notify the sender and delete the original.
--
[ signature omitted ]
Message 5 in thread
>> you can try this:
>>
>> QMatrix m(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); // identity matrix with
>> reversed Y-axis
>> QGraphicsView::setMatrix(m);
>>
>> HTH
>> Albert
> ...
> That's for the output, but what about the mouse coordinates.
> The system will not apply the inverse of the matrix, right?
>
> andreas
>
For tracking mouse events we normally use overloaded methods of QGraphicsScene, e.g.
void MyGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
...
and here you have access to all coordinate systems one can imagine :)
event->pos()
event->scenePos() <- this one you setup with QGraphicsView::setMatrix call
event->screenPos()
HTH
Albert
--
[ signature omitted ]
Message 6 in thread
>
> In the graphics view the x-coordinates are ok, the y-coordinates are not.
>
> Is there an easy way to fix that, not only for output, but also for
> input, that is for remapping mouse coordinates.
Have a look at
http://trolltech.com/developer/task-tracker/index_html?method=entry&id=142894
and its status :-(
\Ralf
--
[ signature omitted ]
Message 7 in thread
Andreas Fabri wrote:
>
> Hello,
>
> In a mathematics oriented application I want my 2D coordinate system
> with an x-axis oriented from left to right, and the y-axis from bottom
> to top.
>
>
> In the graphics view the x-coordinates are ok, the y-coordinates are not.
>
> Is there an easy way to fix that, not only for output, but also for
> input, that is for remapping mouse coordinates.
>
>
What I do for data to screen is:
int y = ry + (((yMax - dy) * rh) / yRange);
where:
y is the screen y coordinate of the data point.
ry is the top left corner of the drawing rectangle.
yMax is the maximum of all data values.
dy is the data value to plot
rh is the height of the drawing rectangle.
yRange is the maximum range of all of the data values.
( yRange can be greater than yMax if yMin is negative)
For screen to data:
int y = yMax - (py - ry) / rh) * yRange);
where:
y is the data value.
py is the y coordinate of the pixel in the drawing rectangle.
all other variables as above.
--
[ signature omitted ]
Message 8 in thread
-------------- Original message ----------------------
From: Ralf Neubersch <rneuber1@xxxxxxxxxxxxxxx>
>
> >
> > In the graphics view the x-coordinates are ok, the y-coordinates are not.
> >
> > Is there an easy way to fix that, not only for output, but also for
> > input, that is for remapping mouse coordinates.
>
> Have a look at
> http://trolltech.com/developer/task-tracker/index_html?method=entry&id=142894
>
> and its status :-(
>
That sounds encouraging to me
Condider it this way: if "The Fix" is as simple as using the transformation matrix mentioned earlier in the thread, then why complicate the library ?
--
[ signature omitted ]