Results 1 to 11 of 11

Thread: Knowing pixel distance between consecutive ticks

  1. #1
    Join Date
    Mar 2006
    Posts
    56
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Knowing pixel distance between consecutive ticks

    Hi all,

    is there a way to know the distance in pixels between two ticks?

    Thank you very much for your help!

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Knowing pixel distance between consecutive ticks

    With plot->axisScaleDiv(...) you find the list of all ticks. With plot_canvasMap(...) you can translate them into pixel positions.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    kalos80 (20th October 2008)

  4. #3
    Join Date
    Mar 2006
    Posts
    56
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Knowing pixel distance between consecutive ticks

    Uwe, thank you very much for your hints.

  5. #4
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Knowing pixel distance between consecutive ticks

    Could anyone please expand on this? I can't understand how to use the QwtScaleMap object to perform said conversion.

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Knowing pixel distance between consecutive ticks

    Quote Originally Posted by frankiefrank View Post
    Could anyone please expand on this? I can't understand how to use the QwtScaleMap object to perform said conversion.
    Qt Code:
    1. QwtScaleMap * scaleMap = myPlot->canvasMap( QwtPlot::xBottom );
    2. int distance_in_pixels = scaleMap->transform( xTick2 ) - scaleMap->transform( xTick1 );
    To copy to clipboard, switch view to plain text mode 

    (From Qwt 5.2; may be different in 6.0 but probably not).

  7. #6
    Join Date
    Dec 2008
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Knowing pixel distance between consecutive ticks

    is there a way to define or set the distance in pixels between consecutive ticks?

  8. #7
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Knowing pixel distance between consecutive ticks

    Quote Originally Posted by barrygp View Post
    is there a way to define or set the distance in pixels between consecutive ticks?
    Unfortunately - no.

    Uwe

  9. #8
    Join Date
    Dec 2008
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Knowing pixel distance between consecutive ticks

    Thanks. If not precise pixels then, is there anyway to change the distance or relative distance between consecutive ticks?

  10. #9
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Knowing pixel distance between consecutive ticks

    Well the ticks even might not be equidistant because of rounding up/down to the closest pixel position ( doubles -> integers ! ).

    In general the ticks are related to scale values - never to widget coordinates. So you have to set up an event filter for the plot canvas adjusting the ticks somehow to the geometry of the canvas.

    Uwe

  11. #10
    Join Date
    Dec 2008
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Knowing pixel distance between consecutive ticks

    Thanks Uwe, that makes sense. I used QwtPlot::setAxisScale() with a defined step number and seems I may be able to work with that.

  12. #11
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Knowing pixel distance between consecutive ticks

    Don't know if it helps, but maybe QwtPlotRescaler offers something useful for you.
    At least it does something similar: QwtPlot::setAxisScale according to resize events of the canvas.

    Uwe

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.