PDA

View Full Version : Reading scenePos by small step



maverick_pol
16th August 2007, 15:05
Hi gusy,

I would like to read sceene position to see the second digit after the coma.
POS -> 00.00.
I am currently using the mouseMoveEvent->sceenePos(), but after converting it to String, I get only an int number( not value after the ',' ). What can I do to read the sceenePos() as a decimal fraction with number after the comma? Maybe the fraction is being casted after creating the QString object?

Thank you for help.

Maverick

wysota
16th August 2007, 15:14
Can we see the code? QString::number() should work fine in conjunction with QPointF::x and QPointF::y.

maverick_pol
16th August 2007, 15:17
I have used a simple QString("%1").arg(QPointF::x());
Ok. will try your idea.

THank you.

Maverick


P.S

I have used this:
QString(QString::number(mouseEvent->scenePos().x())))

but also show only the int part.

Any ideas?

rajesh
17th August 2007, 06:22
I think you write:
QPointF pt = mouseEvent->scenePos();
QString str = QString("%1,%2").arg(pt.x()).arg(pt.y());

maverick_pol
17th August 2007, 08:26
Hi,

I have tried this solution in the first place. It shows only INT values.
Maybe the INT value is read from the scene, and it's not the case of converting it to string. How to read scenePOS with high precision?

Beforehand thanks!

Maverick

marcel
17th August 2007, 08:41
Try QString::setNum(float, char format, int precision).

maverick_pol
17th August 2007, 09:11
Hi,

I will try the QString::setNUM, but I have just used qDebug() to show mouseMoveEvent->scenePos().x(), and it show INT values. It seems that I am reading coordinates as INT values. THe question is: how to read coordinates with higer precision?

Beforehand thanks!

Maverick

P.S.

I have tried using this:


QString wspX;
wspX.setNum(mouseEvent->scenePos().x(),'g',10);
qDebug()<<wspX;


shows only the Decimal values(INTs).

wysota
17th August 2007, 12:49
I think your "problem" is that the fraction part of your coordinates are simply "0" thus the decimal point and zeros that follow are simply discarded. Are you sure the coordinates have non integer values?

maverick_pol
17th August 2007, 12:56
Hi,

I draw a custom background using some VPF data. I create polygon from pair coordinates. There is a lot of coor. like: 3.234, 1.234...etc When I print coord before drawing the background. Because I draw using( example 3.234) coordinate I would like to read the same coordinates with the same precision.
But now I am a bit confused. I need to have a good precision because after zooming the scene 10 times I should be able to see high precision coordinates(3.234) not only the jump from 3->4->5...etc.

Maverick

wysota
17th August 2007, 13:03
Can we see the exact code reproducing the problem?

maverick_pol
17th August 2007, 13:13
I belive that the code is not a problem, rather the understanding of coordinates system.
I am passing from signal to slot the:

mouseEvent->scenePos();
scenePos().x() in the qDebug() show the int, so I belive that I am reading only int values, but need to also read the decimal fraction.

How to do it is the problem.


But...when I zoom, let's say 3 times, I get high precision coordinates.(because the distance between 2 point is bigger, and this maybe be the reason).

wysota
17th August 2007, 14:04
You are getting an integer, because the fraction part is zero. Pixels on the screen are so big (the scale can be 1:1 or smaller) compared to the scene coordinates, that you can't "click" on points that have noninteger coordinates.

maverick_pol
17th August 2007, 14:26
Ok, that's a good point, but I have an application written in MFC that uses CDC to paint my map and show the .xxx values.
And I am suppose to do the same.

Ok, I have just discoverd one thing. When I start the application I get only the INT part of the coordinate, but when I zoom In I get the high precision float(good). Not all.
When I zoom out(the map the same as when I start the app) I get the same high precision float(good), not the INT,even though the map scale is the same as at the begining. ?!!!!!

I have attached screen(when apps start(INT VAL) and after zooming iN/out). Map has the same scale but coords are shown with a different precision)

Maverick

wysota
17th August 2007, 15:34
Could you please ask your application to report the scene size and coordinates on every mouse click or so? My opinion is that your scene size varies and that causes the "malfunction".

maverick_pol
17th August 2007, 18:43
Hi,

While using fitInView(QRect) the scene is being scaled and rotated(if needed) to ensure that the rect is visible(but not always); there are some flags that help to set the best needed transformation.
I am sure that the scene has different size while zooming, etc.
The main question is, why after zooming In and then zooming out I can see the high precision coordinates when the size of the scene is the same as during the app start?
Why I can't see the fraction just after the app starts?
Maybe there is somekind of flag/attribute that changes during the zoomIn/Out connected with coordinates precision?

Maverick

wysota
17th August 2007, 19:44
You can really not respond to my question in your posts, but I'll keep asking the same question over and over - could you report the scene size right after creating it and after each zooming operation? The most probable cause is that the scale of the view changes because of some event that happens during execution of the application (like because the scene size changes) and it causes "fractions" to become available. Could you please use qDebug to report the scene size like I asked you here and in the other thread? Because right now we're getting nowhere.

maverick_pol
21st August 2007, 12:48
Hi,

Excuse me for not being very precise in my posts. I will try to give more details.
Scene/View/_rectangle size :
http://www.qtcentre.org/forum/f-qt-programming-2/t-zooming-scene-rectqt-bug-8625-post46345.html#post46345

Maverick

maverick_pol
22nd August 2007, 10:56
any other ideas?

Beforehand thanks!

Maverick

wysota
24th August 2007, 04:53
Solve the problem from the other thread first.

maverick_pol
24th August 2007, 08:37
I will try to solve the other thread, but that thread seems to be "dead". You were the only person helping me there for a long time. After including the problematic code, noone responded to it.

Maverick

wysota
25th August 2007, 23:44
The thread seems very much alive...