Results 1 to 5 of 5

Thread: Constant Grid

  1. #1

    Question Constant Grid

    Hi,

    I have a timing diagram like this:

    timimng.jpg

    I want a constant grid, for example every 10 ns because this represents e.g. a clock.

    Compare: http://www.texample.net/media/tikz/e...ng-diagram.png

    Any ideas?

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

    Default Re: Constant Grid

    QwtPlotGrid draws major or minor grid lines depending on the ticks it gets from the corresponding scales. So you have the option to modify the scale f.e by setting a step size to 10 - or by modifying the max major, max minor attributes. When you don't need zooming/panning you can even assign the ticks manually ( using QwtPlot::setAxisScaleDiv() ).

    The other option is to have the grid lines independent from the scales. For this you can overload QwtPlotGrid::updateScaleDiv(). Simply replace the ticks in the incoming scaleDiv object by something aligned to 10 and keep its boundaries.

    HTH,
    Uwe

  3. #3

    Default Re: Constant Grid

    I Set the stepsize to 10...

    But, whe I zoom everything changed again

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

    Default Re: Constant Grid

    Quote Originally Posted by myzinsky View Post
    But, whe I zoom everything changed again
    Setting a fixed step size doesn't make too much sense when zooming ( consider a step size of 10 for a range of 5-6 ).

    But as I wrote before - simply decouple the grid from the ticks of the scales by overloading QwtPlotGrid::updateScaleDiv().

    Qt Code:
    1. class YourGrid: public QwtPlotGrid
    2. {
    3. public:
    4. ...
    5. virtual void updateScaleDiv( const QwtScaleDiv& xScaleDiv, const QwtScaleDiv& yScaleDiv )
    6. {
    7. QwtScaleDiv scaleDiv;
    8. scaleDiv.setInterval( xScaleDiv.interval() );
    9.  
    10. double min = xScaleDiv.interval().lowerBound();
    11. double max = xScaleDiv.interval.upperBound();
    12. if ( min > max )
    13. qSwap( min, max );
    14.  
    15. const int stepSize = 10.0;
    16.  
    17. min = static_cast<int>( min / stepSize ) * stepSize;
    18.  
    19. QList<double > ticks;
    20. for ( double tick = min; tick <= max; tick += stepSize )
    21. ticks += tick;
    22.  
    23. scaleDiv.setTicks( QwtScaleDiv::MajorTick, ticks );
    24.  
    25. QwtPlotGrid::updateScaleDiv( scaleDiv, yScaleDiv );
    26. }
    To copy to clipboard, switch view to plain text mode 

    Uwe

  5. #5

    Default Re: Constant Grid

    It works fine!

    But I had to change this:

    Qt Code:
    1. double min = xScaleDiv.interval().minValue();
    2. double max = xScaleDiv.interval().maxValue();
    To copy to clipboard, switch view to plain text mode 

    Tank You Uwe!
    Regards

Similar Threads

  1. yLeft axis constant width
    By baray98 in forum Qwt
    Replies: 4
    Last Post: 4th January 2013, 17:40
  2. Replies: 2
    Last Post: 9th March 2011, 13:27
  3. how to compare a Qstring with a constant char*
    By qt_user in forum Qt Programming
    Replies: 3
    Last Post: 10th August 2010, 04:42
  4. Constant busy cursor when application is run
    By b1 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 10th January 2010, 22:30
  5. QTableView has constant number of rows
    By tomeks in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2008, 16:29

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.