Results 1 to 20 of 21

Thread: Reading scenePos by small step

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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

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.