PDA

View Full Version : Square QwtPlotGrid



drunknight
21st April 2014, 05:31
I have written a QwtPlot on MainWindow,and set it as centreWidget.
Here is the code i wrote based on the Qwt examples:

Plot::Plot( QWidget *parent ):
IncrementalPlot( parent ),
d_timer( 0 )
{
enableAxis(xBottom,false);
enableAxis(yLeft,false);
setAxisMaxMajor(xBottom,17);
setAxisMaxMajor(yLeft,10);

d_rescaler = new QwtPlotRescaler( canvas() );
d_rescaler->setReferenceAxis( QwtPlot::xBottom );
d_rescaler->setAspectRatio( QwtPlot::yLeft, 1.0 );
d_rescaler->setAspectRatio( QwtPlot::yRight, 0.0 );
d_rescaler->setAspectRatio( QwtPlot::xTop, 0.0 );
d_rescaler->setRescalePolicy( QwtPlotRescaler::Expanding );
d_rescaler->setEnabled( true );
d_rescaler->rescale();

plotLayout()->setAlignCanvasToScales( true );

QwtPlotGrid *grid = new QwtPlotGrid;
grid->setMajorPen( Qt::black, 0, Qt::SolidLine );
grid->attach( this );

setCanvasBackground( Qt::gray );

setAxisScale( xBottom, 0, 1000 );
setAxisScale( yLeft, 0, 1000 );
canvas()->setMouseTracking(true);
replot();

// panning with the left mouse button
new QwtPlotPanner( canvas() );

// zoom in/out with the wheel
QwtPlotMagnifier *magnifier = new QwtPlotMagnifier( canvas() );
magnifier->setMouseButton( Qt::NoButton );

picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,canvas());
}

I came as:
10294

I would like to keep the grid square.

But when i zoomed in,it became like this:
10295

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!

Uwe
24th April 2014, 12:03
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

drunknight
14th May 2014, 08:52
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.
10354
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!:)

Uwe
14th May 2014, 10:46
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

drunknight
15th May 2014, 09:02
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!