Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, February 2007
QT4.3 coordinate oddness


Message 1 in thread

Hello-

Just when I thought I had the coordinate stuff nailed,
I find I dont quite know it yet.

Im drawing lines and text onto the QGraphicsView/QGraphicsScene.
All of these values come to me from some other program.
All these values happen to be negative coordinates ie:
line: -500, -450  to -560, -450
etc

I expect something like:

-------                     |
   |                        |
   |       instead I get:   |
   |                     -------

What's odd is that the drawing appears on the screen
to be 'flipped' or mirrored across the X axis and Im
at a loss to figure out why.  Obviously this could easily
be my problem, but I wanted to ask here in case there's
some coordinate gotcha I dont already know about.  Each
item is an individual QGraphicsItem.

Thank you,
Jeff

--
 [ signature omitted ] 

Message 2 in thread

On 28.02.07 00:28:19, Jeff Lacki wrote:
> Im drawing lines and text onto the QGraphicsView/QGraphicsScene.
> All of these values come to me from some other program.
> All these values happen to be negative coordinates ie:
> line: -500, -450  to -560, -450
> etc

Well, thats easily changed by multiplying whatever you get with -1.

> I expect something like:
> 
> -------                     |
>    |                        |
>    |       instead I get:   |
>    |                     -------
> 
> What's odd is that the drawing appears on the screen
> to be 'flipped' or mirrored across the X axis and Im
> at a loss to figure out why.  Obviously this could easily
> be my problem, but I wanted to ask here in case there's
> some coordinate gotcha I dont already know about.  Each
> item is an individual QGraphicsItem.

The question is hardly possible to answer because you don't show any
code how this drawing is to be done. Having had a quick look at the docs
I understood that the coordinate system starts a the upper right corner,
the x axis grows to the left, the y axis to the bottom. If you create a
line with the coordinates x1=10,y1=5,x2=10,y2=15 and then another line
with coordinates x1=0,y1=4,x2=20,y2=4 you should get exactly the result
you were looking for.

Andreas

-- 
 [ signature omitted ] 

Message 3 in thread

Andreas Pakulat wrote:
> On 28.02.07 00:28:19, Jeff Lacki wrote:
>> Im drawing lines and text onto the QGraphicsView/QGraphicsScene.
>> All of these values come to me from some other program.
>> All these values happen to be negative coordinates ie:
>> line: -500, -450  to -560, -450
>> etc
> 
> Well, thats easily changed by multiplying whatever you get with -1.
> 
>> I expect something like:
>>
>> -------                     |
>>    |                        |
>>    |       instead I get:   |
>>    |                     -------
>>
>> What's odd is that the drawing appears on the screen
>> to be 'flipped' or mirrored across the X axis and Im
>> at a loss to figure out why.  Obviously this could easily
>> be my problem, but I wanted to ask here in case there's
>> some coordinate gotcha I dont already know about.  Each
>> item is an individual QGraphicsItem.

> 
> The question is hardly possible to answer because you don't show any
> code how this drawing is to be done. Having had a quick look at the docs
> I understood that the coordinate system starts a the upper right corner,
> the x axis grows to the left, the y axis to the bottom. If you create a
> line with the coordinates x1=10,y1=5,x2=10,y2=15 and then another line
> with coordinates x1=0,y1=4,x2=20,y2=4 you should get exactly the result
> you were looking for.

Actually, I think that the coordinate system starts in the upper left 
corner of the screen. The X axis grows to the right and the Y axis grows 
  downwards. The probable reason that the images are flipped is that 
they were created with a system that has coordinates that start in the 
lower left corner of the screen (such as OpenGL?).
> 
> Andreas
> 

--
 [ signature omitted ] 

Message 4 in thread

On Feb 28, 2007, at 6:16 AM, John McClurkin wrote:

> Andreas Pakulat wrote:
>> On 28.02.07 00:28:19, Jeff Lacki wrote:
>>> Im drawing lines and text onto the QGraphicsView/QGraphicsScene.
>>> All of these values come to me from some other program.
>>> All these values happen to be negative coordinates ie:
>>> line: -500, -450  to -560, -450
>>> etc
>> Well, thats easily changed by multiplying whatever you get with -1.
>>> I expect something like:
>>>
>>> -------                     |
>>>    |                        |
>>>    |       instead I get:   |
>>>    |                     -------
>>>
>>> What's odd is that the drawing appears on the screen
>>> to be 'flipped' or mirrored across the X axis and Im
>>> at a loss to figure out why.  Obviously this could easily
>>> be my problem, but I wanted to ask here in case there's
>>> some coordinate gotcha I dont already know about.  Each
>>> item is an individual QGraphicsItem.
>
>> The question is hardly possible to answer because you don't show any
>> code how this drawing is to be done. Having had a quick look at  
>> the docs
>> I understood that the coordinate system starts a the upper right  
>> corner,
>> the x axis grows to the left, the y axis to the bottom. If you  
>> create a
>> line with the coordinates x1=10,y1=5,x2=10,y2=15 and then another  
>> line
>> with coordinates x1=0,y1=4,x2=20,y2=4 you should get exactly the  
>> result
>> you were looking for.
>
> Actually, I think that the coordinate system starts in the upper  
> left corner of the screen. The X axis grows to the right and the Y  
> axis grows  downwards. The probable reason that the images are  
> flipped is that they were created with a system that has  
> coordinates that start in the lower left corner of the screen (such  
> as OpenGL?).
>> Andreas


I had similar issues.  Even though the coordinate system is  
documented in the view/scene
as having the origin in the upper left, we all grew up learning to  
think of the origin in the
lower left.   I solved the problem by using a call to scale to flip  
the view/scene around
X axis:

     originalDataScene_ = new QGraphicsScene(this);
     ui.originalDataView->setScene(originalDataScene_);
     ui.originalDataView->scale(1.0,-1.0);

-Dennis


--
 [ signature omitted ]