Results 1 to 5 of 5

Thread: Square QwtPlotGrid

  1. #1
    Join Date
    Nov 2013
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question Square QwtPlotGrid

    I have written a QwtPlot on MainWindow,and set it as centreWidget.
    Here is the code i wrote based on the Qwt examples:
    Qt Code:
    1. Plot::Plot( QWidget *parent ):
    2. IncrementalPlot( parent ),
    3. d_timer( 0 )
    4. {
    5. enableAxis(xBottom,false);
    6. enableAxis(yLeft,false);
    7. setAxisMaxMajor(xBottom,17);
    8. setAxisMaxMajor(yLeft,10);
    9.  
    10. d_rescaler = new QwtPlotRescaler( canvas() );
    11. d_rescaler->setReferenceAxis( QwtPlot::xBottom );
    12. d_rescaler->setAspectRatio( QwtPlot::yLeft, 1.0 );
    13. d_rescaler->setAspectRatio( QwtPlot::yRight, 0.0 );
    14. d_rescaler->setAspectRatio( QwtPlot::xTop, 0.0 );
    15. d_rescaler->setRescalePolicy( QwtPlotRescaler::Expanding );
    16. d_rescaler->setEnabled( true );
    17. d_rescaler->rescale();
    18.  
    19. plotLayout()->setAlignCanvasToScales( true );
    20.  
    21. QwtPlotGrid *grid = new QwtPlotGrid;
    22. grid->setMajorPen( Qt::black, 0, Qt::SolidLine );
    23. grid->attach( this );
    24.  
    25. setCanvasBackground( Qt::gray );
    26.  
    27. setAxisScale( xBottom, 0, 1000 );
    28. setAxisScale( yLeft, 0, 1000 );
    29. canvas()->setMouseTracking(true);
    30. replot();
    31.  
    32. // panning with the left mouse button
    33. new QwtPlotPanner( canvas() );
    34.  
    35. // zoom in/out with the wheel
    36. QwtPlotMagnifier *magnifier = new QwtPlotMagnifier( canvas() );
    37. magnifier->setMouseButton( Qt::NoButton );
    38.  
    39. picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,canvas());
    40. }
    To copy to clipboard, switch view to plain text mode 

    I came as:
    Square.png

    I would like to keep the grid square.

    But when i zoomed in,it became like this:
    Rectangular.png

    I have found some information about this,like the grid is bound to the ScaleTicks.
    But i still didn't found the solution.Could anyone help me out?@Uwe?

    Thanks first!

  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: Square QwtPlotGrid

    To have a fixed aspect ratio you can only set one scale - the others have to be calculated depending on the current canvas geometry ( like it is done by QwtPlotRescaler::rescale() ).

    Uwe

  3. #3
    Join Date
    Nov 2013
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Square QwtPlotGrid

    Thanks for your attention,Uwe! We have fixed this this week with your little tip. However, with the program going , now we face another problem. I hope you can give me some advice too.
    QQ截图20140514144741.png
    This is what happened when I was dragging the plot canvas. The curves and grid can't show themselves automatically and simultaneously with the drag action, but right after it.
    Would you help me with this?
    Thanks again!
    Attached Images Attached Images

  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: Square QwtPlotGrid

    Quote Originally Posted by drunknight View Post
    The curves and grid can't show themselves automatically and simultaneously with the drag action, but right after it.
    This is how QwtPlotPanner works - it grabs the content of the plot canvas to an pixmap. Then only the pixmap gets moved while dragging - no replot. The reason for this implementation is because often the replot operation is too slow for fast mouse movements.

    But when you have a lightweight plot and your system is fast enough: don't use QwtPlotPanner and better implement panning yourself. All what needs to be done is to set up an event filter for the plot canvas, where you handle mouse events to translate them into calls of QwtPlot::setAxisScale(). Maybe I will add such a code to a future version of Qwt, but it is so trivial, that I never thought about doing it in the past.

    Uwe

  5. #5
    Join Date
    Nov 2013
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Square QwtPlotGrid

    Users' demands are so diverse and varying. It is almost impossible to meet every need. I appreciate what you have done by writing QwtPlotPanner, and will try implement panning with my colleagues based on your code.

    I will let you know if success! Thanks again,Uwe!

Similar Threads

  1. Problem with QwtPlotGrid
    By wooosh in forum Qwt
    Replies: 2
    Last Post: 5th February 2014, 21:38
  2. qwtplotgrid and qwtscalediv problem
    By tangtao_xp in forum Qwt
    Replies: 9
    Last Post: 15th June 2013, 07:02
  3. Replies: 6
    Last Post: 28th March 2012, 00:11
  4. painting in QwtPlotGrid
    By ready in forum Qwt
    Replies: 2
    Last Post: 18th July 2011, 06:26
  5. Replies: 8
    Last Post: 2nd August 2006, 16:19

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.