Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Reading scenePos by small step

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Reading scenePos by small step

    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
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading scenePos by small step

    Can we see the code? QString::number() should work fine in conjunction with QPointF::x and QPointF::y.

  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading scenePos by small step

    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?
    Last edited by maverick_pol; 16th August 2007 at 15:40.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  4. #4
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Reading scenePos by small step

    I think you write:
    QPointF pt = mouseEvent->scenePos();
    QString str = QString("%1,%2").arg(pt.x()).arg(pt.y());

  5. #5
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading scenePos by small step

    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
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading scenePos by small step


  7. #7
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading scenePos by small step

    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:
    Qt Code:
    1. QString wspX;
    2. wspX.setNum(mouseEvent->scenePos().x(),'g',10);
    3. qDebug()<<wspX;
    To copy to clipboard, switch view to plain text mode 

    shows only the Decimal values(INTs).
    Last edited by maverick_pol; 17th August 2007 at 09:26.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading scenePos by small step

    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?

  9. #9
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading scenePos by small step

    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
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading scenePos by small step

    Can we see the exact code reproducing the problem?

  11. #11
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading scenePos by small step

    I belive that the code is not a problem, rather the understanding of coordinates system.
    I am passing from signal to slot the:
    Qt Code:
    1. mouseEvent->scenePos();
    To copy to clipboard, switch view to plain text mode 
    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).
    Last edited by maverick_pol; 17th August 2007 at 13:30.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading scenePos by small step

    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.

  13. #13
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading scenePos by small step

    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
    Attached Images Attached Images
    Last edited by maverick_pol; 17th August 2007 at 14:39.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading scenePos by small step

    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".

  15. #15
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading scenePos by small step

    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
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading scenePos by small step

    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.

  17. #17
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading scenePos by small step

    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-p...html#post46345

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  18. #18
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading scenePos by small step

    any other ideas?

    Beforehand thanks!

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading scenePos by small step

    Solve the problem from the other thread first.

  20. #20
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reading scenePos by small step

    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
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.