Results 1 to 5 of 5

Thread: Problem with scale ticks

  1. #1
    Join Date
    Oct 2009
    Posts
    13
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Problem with scale ticks

    Hi all,

    I want to display a plot with a fixed number of major and minor ticks and I don't want to display for each major tick the corresponding label.

    This is my code:

    Qt Code:
    1. void Form1::init()
    2. {
    3.  
    4. qwtPlot1->setCanvasBackground(Qt::blue);
    5. QwtPlotGrid *grid=new QwtPlotGrid();
    6. grid->setPen(QPen(Qt::white,0,DotLine));
    7. grid->attach(qwtPlot1);
    8.  
    9.  
    10. QwtValueList xytick[QwtScaleDiv::NTickTypes];
    11. for (int i=0;i<11;i++)
    12. xytick[QwtScaleDiv::MajorTick]<<i/10.0;
    13. for (int i=0;i<61;i++)
    14. xytick[QwtScaleDiv::MinorTick]<<i/60.0;
    15.  
    16.  
    17. qwtPlot1->enableAxis(QwtPlot::xTop,true);
    18. qwtPlot1->enableAxis(QwtPlot::yRight,true);
    19.  
    20.  
    21. qwtPlot1->setAxisScaleDiv(QwtPlot::xBottom,QwtScaleDiv(0.0,1.0,xytick));
    22. qwtPlot1->setAxisScaleDiv(QwtPlot::xTop,QwtScaleDiv(0.0,1.0,xytick));
    23. qwtPlot1->setAxisScaleDiv(QwtPlot::yLeft,QwtScaleDiv(0.0,1.0,xytick));
    24. qwtPlot1->setAxisScaleDiv(QwtPlot::yRight,QwtScaleDiv(0.0,1.0,xytick));
    25.  
    26. qwtPlot1->setAxisScaleDraw(QwtPlot::xBottom,new NullScaleDraw());
    27. qwtPlot1->setAxisScaleDraw(QwtPlot::xTop,new NullScaleDraw());
    28. qwtPlot1->setAxisScaleDraw(QwtPlot::yLeft,new NullScaleDraw());
    29. qwtPlot1->setAxisScaleDraw(QwtPlot::yRight,new NullScaleDraw());
    30. }
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. class NullScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. NullScaleDraw()
    5. {
    6. }
    7. virtual QwtText label(double v) const
    8. {
    9. return QString("");
    10. }
    11. };
    To copy to clipboard, switch view to plain text mode 

    This gives me the output displayed in the attached file qwtplot.jpg.

    My question is why the last major ticks of both xBottom and xTop and the first major ticks of both yLeft and yRight axis disappear when I call qwtPlot1->setAxisScaleDraw(...,new NullScaleDraw)?

    Is it possible to avoid the displaying of the tick labels in an easier way?

    Thanks a lot for you help.

    Best regards
    Attached Images Attached Images

  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: Problem with scale ticks

    Quote Originally Posted by gd View Post
    Is it possible to avoid the displaying of the tick labels in an easier way?
    Don't know if this is easier, but you could use medium instead of major ticks. The tick length can be changed using QwtAbstractScaleDraw::setTickLength().

    Uwe

  3. #3
    Join Date
    Oct 2009
    Posts
    13
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Problem with scale ticks

    Dear Uwe,

    thanks for the suggestion I will try it.

    But anyway why using my code the last and the first major ticks disappear? What is wrong with my code?

    Thanks again to be a very helpful person.

    Best regards

  4. #4
    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: Problem with scale ticks

    I forgot - there is a simple solution:
    Qt Code:
    1. plot->axisScaleDraw(...)->enableComponent(QwtAbstractScaleDraw::Labels, false);
    To copy to clipboard, switch view to plain text mode 
    But anyway why using my code the last and the first major ticks disappear?
    Looks like a bug in the layout engine of the plot widget- the axis widgets are one pixel too small and the last tick is painted outside. If you can live with a pointless margin a possible workaround is to return a dummy blank for one of your tick labels.

    Uwe

  5. #5
    Join Date
    Oct 2009
    Posts
    13
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Problem with scale ticks

    Quote Originally Posted by Uwe View Post
    If you can live with a pointless margin a possible workaround is to return a dummy blank for one of your tick labels.

    Really thanks! I have solved in that way!

    Best regards

Similar Threads

  1. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.