Enable/Disable Zoom with a checkable action
Hi all,
i need some help regarding the following issue. I have a QwtPlot with some functionalities on right mouse click.
Code:
{
contextMenu.addAction(printAct);
contextMenu.addAction(printPDFAct);
contextMenu.addAction(saveasAct);
contextMenu.addAction(zoomAct);
contextMenu.addAction(showGridAct);
contextMenu.exec(event->globalPos());
}
I want to be able to enable or disable my zoomer with a checkable action. I can enable the zoom by clicking my action but as i uncheck the action, the zoomer is still enabled. Can someone tell me what am i doing wrong?
Action is declared in my ctor like:
Code:
this->zoomAct->setCheckable(true);
this->zoomAct->setChecked(false);
I connect the action with:
Code:
QObject::connect(this
->zoomAct,
SIGNAL(toggled
(bool)),
this,
SLOT(enableZoomMode
(bool)));
And the enableZoomMode function looks like:
Code:
void Sys_Plot_Wid::enableZoomMode(bool on)
{
plotMagnifier->setMouseButton(Qt::MidButton);
plotMagnifier->setEnabled(on);
plotPanner->setMouseButton(Qt::LeftButton);
plotPanner->setEnabled(on);
plotZoomer->setMousePattern(0, Qt::LeftButton, Qt::ControlModifier);
plotZoomer->setMousePattern(1, Qt::MidButton);
plotZoomer->setMousePattern(2, Qt::NoButton);
plotZoomer->setEnabled(on);
picker
->setRubberBandPen
(QColor(Qt
::darkCyan));
picker
->setRubberBand
(QwtPicker::CrossRubberBand);
picker->setEnabled(!on);
this->replot();
}
Thanks for your replies.
Re: Enable/Disable Zoom with a checkable action
You shouldn't be creating new zoomers, pickers, etc. every time you toggle. Create them once and the slot should only enable and disable them.
Re: Enable/Disable Zoom with a checkable action
Basic C++ Knowledges were required :o. Thx a lot.