生活随笔
收集整理的這篇文章主要介紹了
Qwt Plot Magnifier 缩放以鼠标为中心
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Qwt Plot Magnifier 縮放以鼠標為中心
問題
使用QwtPlotMagnifier時,用滾輪縮放時,縮放中心是QwtPlot的中間。
現需要改成在鼠標中間進行縮放
功能預覽
更改
創建MyPlotMagnifier,并繼承QwtPlotMagnifier重寫rescale函數,將源碼中的rescale復制修改如下部分
void MyPlotMagnifier
::rescale( double factor
)
{QwtPlot
* plt
= plot();if ( plt
== NULL )return;factor
= qAbs( factor
);if ( factor
== 1.0 || factor
== 0.0 )return;bool doReplot
= false;const bool autoReplot
= plt
->autoReplot();plt
->setAutoReplot( false );QPoint cursorPos
= canvas()->mapFromGlobal(canvas()->cursor().pos());for ( int axisId
= 0; axisId
< QwtPlot
::axisCnt
; axisId
++ ){if ( isAxisEnabled( axisId
) ){const QwtScaleMap scaleMap
= plt
->canvasMap( axisId
);double v1
= scaleMap
.s1();double v2
= scaleMap
.s2();if ( scaleMap
.transformation() ){v1
= scaleMap
.transform( v1
); v2
= scaleMap
.transform( v2
); }
const double posInAxis
= (axisId
/2?cursorPos
.x():cursorPos
.y());const double lenthInAxis
= (axisId
/2?canvas()->rect().width():canvas()->rect().height());double posRadio
= posInAxis
/ lenthInAxis
;if(axisId
/2 == 0){posRadio
= 1-posRadio
;}double center
= posRadio
* ( v2
- v1
) + v1
;v1
= center
- (center
-v1
) * factor
;v2
= center
+ (v2
- center
) * factor
;if ( scaleMap
.transformation() ){v1
= scaleMap
.invTransform( v1
);v2
= scaleMap
.invTransform( v2
);}plt
->setAxisScale( axisId
, v1
, v2
);doReplot
= true;}}plt
->setAutoReplot( autoReplot
);if ( doReplot
)plt
->replot();
}``
總結
以上是生活随笔為你收集整理的Qwt Plot Magnifier 缩放以鼠标为中心的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。