Results 1 to 4 of 4

Thread: scale in QwtSlider and QwtPlot

  1. #1
    Join Date
    May 2009
    Posts
    75
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default scale in QwtSlider and QwtPlot

    I have a QwtSlider with range (for example) [2, 17]

    When it is drawn the scale is "unclear":
    qwtSliderScaleExample.png

    the uppoer and lower value are not explicitly shown.

    similar problem is on QwtPlot scale.

    Can I change the scale to show the upper and lower value?

    best regards
    max

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

    Default Re: scale in QwtSlider and QwtPlot

    The boundaries of a scale and the position of all ticks are defined by a QwtScaleDiv object. Tick labels are painted for major ticks.
    A scale division can be assigned manually from application code or can be aligned/calculated by a QwtScaleEngine from its boundaries and a step size. A scale engine implements 2 algorithms:


    • aligning the boundaries
      see QwtScaleEngine::autoScale()
    • finding the ticks
      see QwtScaleEngine::divideScale()


    Each type of scale engine offers parameters that have an impact on its algorithm.

    In case of a slider calculating the scale div manually ( QwtAbstractScale::setScale( const QwtScaleDiv & ) ) might be an option, but in case of plot axes the application code often doesn't know about the scales - f.e. when your plot offers any type of navigation ( zooming, panning ... ) - and you need to have an algo for calculating boundaries and ticks.

    In case of QwtSlider most relevant methods can be found in its base class QwtAbstractScale.

    HTH,
    Uwe

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

    mastupristi (19th October 2014)

  4. #3
    Join Date
    May 2009
    Posts
    75
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: scale in QwtSlider and QwtPlot

    I have inherit a QwtScaleEngine in this way:

    Qt Code:
    1. class boundScaleEngine : public QwtLinearScaleEngine
    2. {
    3. public:
    4.  
    5. virtual QwtScaleDiv divideScale( double x1, double x2,
    6. int numMajorSteps, int numMinorSteps,
    7. double stepSize = 0.0 ) const;
    8. };
    9.  
    10. QwtScaleDiv boundScaleEngine::divideScale( double x1, double x2,
    11. int numMajorSteps, int numMinorSteps,
    12. double stepSize) const
    13. {
    14. QwtScaleDiv sd = QwtLinearScaleEngine::divideScale(x1, x2, numMajorSteps, numMinorSteps, stepSize);
    15.  
    16. QList<double> ticks[QwtScaleDiv::NTickTypes];
    17.  
    18. ticks[QwtScaleDiv::MajorTick] = sd.ticks(QwtScaleDiv::MajorTick);
    19. ticks[QwtScaleDiv::MediumTick] = sd.ticks(QwtScaleDiv::MediumTick);
    20. ticks[QwtScaleDiv::MinorTick] = sd.ticks(QwtScaleDiv::MinorTick);
    21.  
    22. QwtInterval interval = sd.interval();
    23. double upper,lower;
    24.  
    25. if(x1>x2)
    26. {
    27. upper = x1;
    28. lower = x2;
    29. }
    30. else
    31. {
    32. upper = x2;
    33. lower = x1;
    34. }
    35.  
    36. if(ticks[QwtScaleDiv::MajorTick].indexOf(lower) == -1)
    37. ticks[QwtScaleDiv::MajorTick].prepend(lower); // add the lower bound tick if it is not present
    38. if(ticks[QwtScaleDiv::MajorTick].indexOf(upper) == -1)
    39. ticks[QwtScaleDiv::MajorTick].append(upper); // add the upper bound tick if it is not present
    40.  
    41. return QwtScaleDiv(interval, ticks);
    42. }
    To copy to clipboard, switch view to plain text mode 

    I used the boundScaleEngine class in both QwtSlider and QwtPlot, and it seems to work properly, but I don't know if there is some pitfalls.
    what is your opinion?

    bets regards
    max

  5. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,241
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: scale in QwtSlider and QwtPlot

    Quote Originally Posted by mastupristi View Post
    I used the boundScaleEngine class in both QwtSlider and QwtPlot, and it seems to work properly, but I don't know if there is some pitfalls.
    what is your opinion?
    You have to take care of layout issues: the tick labels at the borders might overlap, when being too close to its neighbors.

    Uwe

Similar Threads

  1. How to hide part of a QwtPlot scale?
    By Momergil in forum Qwt
    Replies: 2
    Last Post: 6th February 2013, 19:41
  2. Align QwtSlider and QwtPlot
    By justoit in forum Qwt
    Replies: 4
    Last Post: 4th May 2011, 11:41
  3. Replies: 2
    Last Post: 30th December 2010, 17:32
  4. QwtScale and QwtPlot scale inconsistency.
    By umituzun84 in forum Qwt
    Replies: 5
    Last Post: 18th June 2010, 11:25
  5. QwtPlotItem inverting qwtPlot scale
    By jmsbc in forum Qwt
    Replies: 1
    Last Post: 25th August 2009, 14:09

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.