PDA

View Full Version : How to add Button on Legend to enable/disable QwtPlotZoomer ?



npatil15
17th January 2019, 05:35
Hi Everyone,

I have working on graph, where I have using 2 vertical and 2 horizontal lines(Draggable and droppable along the graph).
Not if I enable QwtPlotZoomer then while dragging Lines on the graph QwtPlotZoomer takes control, so on that node dragging and zooming both comes into effect.
Here I want a small button or something on the Legend which help me to enable or disable QwtPlotZoomer, so that on dragging lines zooming should not work and vice versa.

Thanks :)

ghorwin
17th January 2019, 11:02
Hi ??? [npatil15],

there's an easy way to avoid zooming while dragging - define an additional keyboard modifier to distinguish between dragging or zooming.

If you really want a button, simply create a new curve, make the line attribute NoLine and make the legend button reacting on mouse clicks (see explanation in QwtBook https://ghorwin.github.io/qwtbook/interaction/#auf-checkedunchecked-ereignisse-reagieren)

Bye,
Andreas

npatil15
17th January 2019, 13:23
Thanks ghorwin,

Yes by setting additional keyword will help but that's not the task.
And the link/knowledge you share it surely help me for my next task. But now I have some different pain.

Here I'm unable to add any linked instance, button or something like below code for QwtPlotZoomer, where I can click and do something for this clicked event.
(say setItemAttribute(QwtPlotItem::Legend, true);)

npatil15
21st January 2019, 13:03
Please anyone has any solution or suggestions over it ?

npatil15
22nd January 2019, 10:42
Hi ghorwin,

Can you just tell me how I can use ctrl to switch between zoom and dragging option ?
I don't understand properly how to use setMousePattern to enable plot zoomer.

Thanks

Added after 1 6 minutes:

I have done this, just for the reference I'll mention it here,

m_zoomer = new QwtPlotZoomer(QwtPlot::xBottom, QwtPlot::yLeft, m_plot->canvas());
m_zoomer->setMousePattern(QwtEventPattern::MouseSelect1,Qt:: LeftButton, Qt::ControlModifier);

:cool:

npatil15
24th January 2019, 12:40
Hi,

I'm facing issue regarding the same again,
I still need PushButton on legend, and other marker should not override on it.

I have done line this below,

QPushButton *detachLegendButton = new QPushButton("Toggle attached", m_legend->contentsWidget());

But here this button is come over one of the QwtPlotMarker.

Please suggest, how I can do that ?

npatil15
25th January 2019, 11:01
I have done it,
Answer is mention at the end of this post
https://www.qtcentre.org/threads/69942-QqtPlot-setAxisLabelRotation-doesnt-work-on-zoom-(QwtPlotMagnifier)?p=304315

:cool: