Results 1 to 4 of 4

Thread: How to use explicit labels/ticks?

  1. #1
    Join Date
    Jan 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question How to use explicit labels/ticks?

    Hi, I have very newbie-style problem.
    I've written this code:
    Qt Code:
    1. #include "qwt_plot.h"
    2. #include "qwt_scale_div.h"
    3. #include <QApplication>
    4.  
    5. int main(int argc, char ** argv) {
    6. QApplication app(argc, argv);
    7.  
    8. QwtPlot plot;
    9. plot.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    10. plot.setCanvasBackground(Qt::white);
    11. plot.setAxisScale(QwtPlot::yLeft, 0, 50);
    12.  
    13. QList<double> ticks = QList<double>()
    14. << 10
    15. << 40
    16. << 90;
    17. QwtScaleDiv pressScaleDiv;
    18. pressScaleDiv.setTicks(QwtScaleDiv::MajorTick, ticks);
    19. plot.setAxisScaleDiv(QwtPlot::yLeft, pressScaleDiv);
    20.  
    21. plot.show();
    22. return app.exec();
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 

    My wish is, that y axis has ticks and labels at values 10, 40, 90.
    It seems like code above gives no effect - labels are at 0, 10, 20, 30, 40, 50 + intermediate ticks.
    What am I doing wrong?
    I suspect that the error is trivial ....

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

    Default Re: How to use explicit labels/ticks?

    A QwtScaleDiv consists of the range of a scale and the positions of its ticks. Your code creates an invalid QwtScaleDiv object for 2 reasons:


    1. it doesn't have a range
    2. QwtScaleDiv::isValid() is only true, when using the constructor with a valid range



    The second reason is left over from the very early Qwt versions - it should have never been like this. That's why the isValid() flag has been removed in Qwt 6.1.

    Uwe

    PS: The line with setAxisScale() is pointless, when you assign a different scale a couple of lines below

  3. #3
    Join Date
    Jan 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to use explicit labels/ticks?

    Thanks, Uwe.
    I've improved my wonderful code:
    Qt Code:
    1. #include "qwt_plot.h"
    2. #include "qwt_scale_div.h"
    3. #include <QApplication>
    4.  
    5. int main(int argc, char ** argv) {
    6. QApplication app(argc, argv);
    7.  
    8. QwtPlot plot;
    9. plot.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    10. plot.setCanvasBackground(Qt::white);
    11.  
    12.  
    13. QList<double> ticks[QwtScaleDiv::NTickTypes] = {
    14. QList<double>(),
    15. QList<double>(),
    16. QList<double>()
    17. << 10
    18. << 40
    19. << 90
    20. };
    21. QwtScaleDiv pressScaleDiv(0, 100, ticks);
    22.  
    23. // QwtScaleDiv pressScaleDiv;
    24. // pressScaleDiv.setInterval(0, 100);
    25. // pressScaleDiv.setTicks(
    26. // QwtScaleDiv::MinorMajor,
    27. // QList<double>()
    28. // << 10
    29. // << 40
    30. // << 90
    31. // );
    32. plot.setAxisScaleDiv(QwtPlot::yLeft, pressScaleDiv);
    33.  
    34. plot.show();
    35. return app.exec();
    36.  
    37. }
    To copy to clipboard, switch view to plain text mode 

    and it works - but when I use the commented section instead of the working one above - it doesn't. No problem for me, anyway.
    Thanks a lot.

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

    Default Re: How to use explicit labels/ticks?

    Quote Originally Posted by ssample View Post
    but when I use the commented section instead of the working one above - it doesn't.
    That's because of what I wrote as 2.). The code would be o.k. for Qwt 6.1, but all earlier versions ( starting with Qwt 0.1 ) have this nasty QwtScaleDiv default constructor.

    Uwe

Similar Threads

  1. Replies: 1
    Last Post: 25th June 2014, 11:45
  2. Replies: 14
    Last Post: 30th October 2012, 16:45
  3. Replies: 3
    Last Post: 14th February 2012, 13:37
  4. Replies: 1
    Last Post: 16th March 2010, 16:23
  5. Implicit vs. explicit
    By lni in forum Qt Programming
    Replies: 4
    Last Post: 22nd September 2009, 03:26

Tags for this Thread

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.