Results 1 to 10 of 10

Thread: qwtplotgrid and qwtscalediv problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qwtplotgrid and qwtscalediv problem

    In my case, scale is 150, I want:

    major ticks: (0, 75, 150) --> QPen(Qt::black, 1, Qt::SolidLine)
    medium tickes: (15, 30, 45, 60, 90, 105, 120, 135) --> QPen(Qt::gray, 1, Qt:ashLine)
    minor tickes: (5, 10, 20, 25, 35, 40, 50, 55, 65, 70, 80, 85, 95, 100, 110, 115, 125, 130) --> no painted grid lines

    I tried:

    Qt Code:
    1. QList<double> majorTicks;
    2. majorTicks << 0 << 75 << 150;
    3.  
    4. QList<double> mediumTicks;
    5. mediumTicks << 15 << 30 << 45 << 60 << 90 << 105 << 120 << 135;
    6.  
    7. QList<double> minorTicks;
    8. minorTicks << 5 << 10 << 20 << 25 << 35 << 40 << 50 << 55 << 65
    9. << 70 << 80 << 85 << 95 << 100 << 110 << 115 << 125 << 130;
    10.  
    11. div.setTicks(QwtScaleDiv::MajorTick, majorTicks);
    12. div.setTicks(QwtScaleDiv::MediumTick, mediumTicks);
    13. div.setTicks(QwtScaleDiv::MinorTick, minorTicks);
    14.  
    15. plots[i]->setAxisScale(QwtPlot::xTop, 0, 150);
    16. //plots[i]->setAxisScaleDiv(QwtPlot::xTop, div);
    17. grids[i]->setXDiv(div);
    To copy to clipboard, switch view to plain text mode 

    still failed. Need helps!


    Tang Tao

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

    Default Re: qwtplotgrid and qwtscalediv problem

    The idea of using setAxisScaleDiv is the right one, but now the answer depends on what Qwt version you are using. When using Qwt < 6.1 you always have to use the following constructor:

    Qt Code:
    1. QwtScaleDiv::QwtScaleDiv( const QwtInterval &, QList<double> ticks[NTickTypes] );
    To copy to clipboard, switch view to plain text mode 
    This is the only way to have an object where isValid() is true.

    In Qwt 6.1 this nasty valid flag ( better don't ask what it was good for ) has been moved to where it belongs and you can use QwtScaleDiv like everyone expects that it can be used.

    Uwe

  3. #3
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qwtplotgrid and qwtscalediv problem

    Hi, Uwe

    I really appreciate your reply. I am using the latest version of qwt (v6.1).
    However, I am still confused about you answer. Are you glad to explain more clear for me?

    And why I set the right div-object(in post #2) and it doesn't take effect?


    Tang Tao

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

    Default Re: qwtplotgrid and qwtscalediv problem

    Fixing the code from your second posting:

    Qt Code:
    1. QwtScaleDiv div( 0, 150 );
    2. div.setTicks(QwtScaleDiv::MajorTick, majorTicks);
    3. div.setTicks(QwtScaleDiv::MediumTick, mediumTicks);
    4. div.setTicks(QwtScaleDiv::MinorTick, minorTicks);
    5. plots[i]->setAxisScaleDiv(QwtPlot::xTop, div);
    To copy to clipboard, switch view to plain text mode 

    When you want to have the grid lines independent from the scale ticks you have to set the QwtPlotItem::ScaleInterest flag of the grid item to false. Then the settings done for the grid won't be overwritten by the next replot.

    Uwe

  5. #5
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qwtplotgrid and qwtscalediv problem

    hi, Uwe

    Sorry for late reply.

    I think I want the grid to be decided by the QwtPlot::xTop scale. As your told, my plot has the right ticks at the xTop-scale now.

    But the action of grid line is not what I expect.

    grid1.jpg

    You can see that, in the picture:

    at x = 15, 45, 105, 135, the vertical grid lines is the minor grid lines(gray, dashline).

    at x = 30, 60, 90, 120, the vertical grid lines is the major grid lines(black, soildline).

    what I want is:

    at x = 15, 30, 45, 60, 90, 105, 135, the vertical grid lines is the minor grid lines(gray, dashline)
    at x = 0, 75, 150, the vertical grid lines is the major grid lines(black, soildline)


    does that mean I should overload QwtPlotGrid::draw()?


    Thank you!


    Tang Tao

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

    Default Re: qwtplotgrid and qwtscalediv problem

    Quote Originally Posted by tangtao_xp View Post
    at x = 15, 30, 45, 60, 90, 105, 135, the vertical grid lines is the minor grid lines(gray, dashline)
    at x = 0, 75, 150, the vertical grid lines is the major grid lines(black, soildline)
    When using setAxisScaleDiv() the ticks will be exactly, where you have defined them. Of course another call of setAxisScale() or setAxisAutoScale() for the same axis will overwrite your definition.

    Quote Originally Posted by tangtao_xp View Post
    does that mean I should overload QwtPlotGrid::draw()?
    No all what needs to done is to define range and ticks in a QwtScaleDiv object and assign it to the scale. The grid will be synchronized to it in the next replot.

    Uwe

  7. #7
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qwtplotgrid and qwtscalediv problem

    hi, Uwe

    When using setAxisScaleDiv() the ticks will be exactly, where you have defined them. Of course another call of setAxisScale() or setAxisAutoScale() for the same axis will overwrite your definition.
    I checked my code again and I do not found another call of div defining function(so my definition won't be overwrited). I will give all code below.
    And the grid lines are never synchronized to the scale. And plot picture is the same with post#6

    my code:

    Qt Code:
    1. void MainWindow::setWidget()
    2. {
    3. for (int i = 0; i < 1; i++)
    4. {
    5. plots[i] = new QwtPlot(mainFrame);
    6.  
    7. plots[i]->plotLayout()->setAlignCanvasToScales(true);
    8.  
    9. for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    10. plots[i]->axisWidget(axis)->setMargin( 0 );
    11.  
    12. QwtPlotCanvas *canvas = new QwtPlotCanvas();
    13. canvas->setFrameStyle(QFrame::Plain | QFrame::NoFrame);
    14. plots[i]->setCanvas(canvas);
    15.  
    16. plots[i]->enableAxis(QwtPlot::xBottom, false);
    17. plots[i]->enableAxis(QwtPlot::yRight, false);
    18. plots[i]->enableAxis(QwtPlot::xTop, true);
    19. plots[i]->enableAxis(QwtPlot::yLeft,true);
    20.  
    21. grids[i] = new QwtPlotGrid();
    22. grids[i]->enableX(true);
    23. grids[i]->enableXMin(true);
    24.  
    25. grids[i]->setMajorPen(Qt::black, 1, Qt::SolidLine);
    26. grids[i]->setMinorPen(Qt::gray, 1, Qt::DashLine);
    27.  
    28. QwtScaleDiv div(0, 150);
    29.  
    30. QList<double> majorTicks;
    31. majorTicks << 0 << 75 << 150;
    32.  
    33. QList<double> mediumTicks;
    34. mediumTicks << 15 << 30 << 45 << 60 << 90 << 105 << 120 << 135;
    35.  
    36. div.setTicks(QwtScaleDiv::MajorTick, majorTicks);
    37. div.setTicks(QwtScaleDiv::MediumTick, mediumTicks);
    38.  
    39. plots[i]->setAxisScaleDiv(QwtPlot::xTop, div);
    40.  
    41. grids[i]->attach(plots[i]);
    42.  
    43. // picker
    44. pickers[i] = new QwtPlotPicker(plots[i]->canvas());
    45. pickers[i]->setTrackerMode(QwtPlotPicker::AlwaysOn);
    46. }
    47. }
    To copy to clipboard, switch view to plain text mode 



    No all what needs to done is to define range and ticks in a QwtScaleDiv object and assign it to the scale. The grid will be synchronized to it in the next replot.
    Yes, I agree with you. In my code, I just want to simplify the problem for better understanding, for that english is not my mother tongue.

    As far as I know, in qwt, we can take advantage of setAxisAutoScale() and QwtScaleEnginee class to auto-calculate the tricks. (I wish discuss with you after the first problem done)


    Thank you for your patient help.



    Tang Tao

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

    Default Re: qwtplotgrid and qwtscalediv problem

    I modified the bode example this way:

    In plot.cpp I added the following lines:

    Qt Code:
    1. enableAxis( QwtPlot::xTop );
    2. grid->setXAxis( QwtPlot::xTop ); // did you miss this one ???
    To copy to clipboard, switch view to plain text mode 
    In mainwindow.cpp I replaced the implementation of MainWindow::print():

    Qt Code:
    1. void MainWindow::print()
    2. {
    3. QList<double> majorTicks;
    4. majorTicks << 0 << 75 << 150;
    5.  
    6. QList<double> mediumTicks;
    7. mediumTicks << 15 << 30 << 45 << 60 << 90 << 105 << 120 << 135;
    8.  
    9. QList<double> minorTicks;
    10. minorTicks << 5 << 10 << 20 << 25 << 35 << 40 << 50 << 55 << 65
    11. << 70 << 80 << 85 << 95 << 100 << 110 << 115 << 125 << 130;
    12.  
    13. QwtScaleDiv div( 0, 150 );
    14. div.setTicks(QwtScaleDiv::MajorTick, majorTicks);
    15. div.setTicks(QwtScaleDiv::MediumTick, mediumTicks);
    16. div.setTicks(QwtScaleDiv::MinorTick, minorTicks);
    17. d_plot->setAxisScaleDiv(QwtPlot::xTop, div);
    18. }
    To copy to clipboard, switch view to plain text mode 
    When pressing "Print" the scale looks like expected and the grid lines are aligned to the ticks.

    Uwe

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

    tangtao_xp (15th June 2013)

  10. #9
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qwtplotgrid and qwtscalediv problem

    Quote Originally Posted by Uwe View Post
    I modified the bode example this way:

    In plot.cpp I added the following lines:

    Qt Code:
    1. enableAxis( QwtPlot::xTop );
    2. grid->setXAxis( QwtPlot::xTop ); // did you miss this one ???
    To copy to clipboard, switch view to plain text mode 
    In mainwindow.cpp I replaced the implementation of MainWindow:rint():
    It works! Thank you, Uwe!

    I think the reason why code does not take effect is that the grid synchronizes with the x-bottom axis by default.
    And I should change this default action of grid by setXAxis(QwtPlot::xTop) .

    Now, I move to how to auto-calculate the ticks both in linearscale and logscale. If I had a trouble with that, I will post out.

    Thank you again!



    Tang Tao

Similar Threads

  1. Replies: 3
    Last Post: 11th March 2013, 07:31
  2. Replies: 6
    Last Post: 28th March 2012, 00:11
  3. Replies: 2
    Last Post: 3rd March 2012, 12:51
  4. An error in QwtScaleDiv::invert
    By alex_sh in forum Qwt
    Replies: 3
    Last Post: 12th January 2012, 13:25
  5. painting in QwtPlotGrid
    By ready in forum Qwt
    Replies: 2
    Last Post: 18th July 2011, 06:26

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
  •  
Qt is a trademark of The Qt Company.