redraw the axes of a QwtPlot during a panning (QwtPlotPanner)
I'm using QWT 6.0.1 RC5, QT 4.8.0
I added a QwtPlotPanner in a QwtPlot and I would like axes were moving simultaneously to the shift of the canvas and not only once the panner is finished.
Then I associated a slot to the signal move (int dx , int dy) of the QwtPlotPanner :
note :cart is a QwtPlot.
Code:
scaleMapTmpX.
setScaleInterval(cart
->axisScaleDiv
(QwtPlot::xBottom)->upperBound
(),
cart
->axisScaleDiv
(QwtPlot::xBottom)->lowerBound
());
scaleMapTmpY.
setScaleInterval(cart
->axisScaleDiv
(QwtPlot::yLeft)->upperBound
(),
cart
->axisScaleDiv
(QwtPlot::yLeft)->lowerBound
());
double zoomPlotDragLowerBoundX
= cart
->axisScaleDiv
(QwtPlot::xBottom)->lowerBound
();
double zoomPlotDragUpperBoundX
= cart
->axisScaleDiv
(QwtPlot::xBottom)->upperBound
();
double zoomPlotDragLowerBoundY
= cart
->axisScaleDiv
(QwtPlot::yLeft)->lowerBound
();
double zoomPlotDragUpperBoundY
= cart
->axisScaleDiv
(QwtPlot::yLeft)->upperBound
();
double LowerBoundX = scaleMapTmpX.transform(zoomPlotDragLowerBoundX);
double UpperBoundX = scaleMapTmpX.transform(zoomPlotDragUpperBoundX);
double LowerBoundY = scaleMapTmpY.transform(zoomPlotDragLowerBoundY);
double UpperBoundY = scaleMapTmpY.transform(zoomPlotDragUpperBoundY);
cart
->setAxisScale
(QwtPlot::yLeft, scaleMapTmpY.
invTransform(LowerBoundY
+ dy
) ,
scaleMapTmpY.invTransform(UpperBoundY + dy) );
cart
->setAxisScale
(QwtPlot::xBottom, scaleMapTmpX.
invTransform(LowerBoundX
+ dx
) ,
scaleMapTmpX.invTransform(UpperBoundX + dx ));
cart->replot();
In the posted code the axes aren't correctly redraw (in partular the shift isn't conveted in the right scale). Do you have a solution?
In the implementation of the signal move(int dx, int dy), dx and dy represent the offset in pixel or in another unit of measure?
Re: redraw the axes of a QwtPlot during a panning (QwtPlotPanner)
Quote:
Originally Posted by
gaia86
I added a QwtPlotPanner in a QwtPlot and I would like axes were moving simultaneously to the shift of the canvas and not only once the panner is finished.
Then don't use QwtPlotPanner. Instead install an event filter for the plot canvas handling its mouse events. Translate them into calls of QwtPlot:.setAxisScale + QwtPlot::replot();
But be aware of jumping scales ( modifiying the size of the canvas ) + potential performance issues for complex scenes.
Uwe
Re: redraw the axes of a QwtPlot during a panning (QwtPlotPanner)
Very old thread and I'm not the OP, but I finally got around to implementing this, so I'll leave it here in case anyone is looking for an example. :)
I handled it with a QwtPlotZoomer (m_zoomer) and update the zoom() based on the mouse movement while the middle mouse button is down. It's quite fast, even on large plots and is immune to changes in the plot size.
I store the mouse drag location (m_mouseDragLocation) when the middle button is first pressed and then update it after each 1px movement during a drag operation.
Then, inside QwtPlot::eventFilter()
Code:
// MouseMove only fires while a mouse button is pressed
if (event
->type
() == QEvent::MouseMove) {
// User wants to pan the plot
if (m_middleMouseDown)
{
// Get current zoom rectangle
QRectF zoomRect
= m_zoomer
->zoomRect
();
// Convert the change in position for the last drag (1px) from
// pixel space to plot space.
double deltaX
= invTransform
(QwtPlot::xBottom, m_mouseDragLocation.
x()) - invTransform
(QwtPlot::xBottom, cursor
().
pos().
x());
double deltaY
= invTransform
(QwtPlot::yLeft, m_mouseDragLocation.
y()) - invTransform
(QwtPlot::yLeft, cursor
().
pos().
y());
// Update the zoom rect with the new values
zoomRect.setX(zoomRect.x() + deltaX);
zoomRect.setY(zoomRect.y() + deltaY);
zoomRect.setWidth (zoomRect.width() + deltaX);
zoomRect.setHeight(zoomRect.height() + deltaY);
// Store for continued dragging
m_mouseDragLocation = cursor().pos();
// Set the zoom to its new position
m_zoomer->zoom(zoomRect);
}
}