Because the zoomer/picker is not always enabled in my case,...
Then change things up a little bit.
#include <QApplication>
#include <qwt_plot.h>
#include <qwt_plot_zoomer.h>
#include <QEvent>
{
public:
{
}
{
_zoomer = zoomer;
}
protected:
void changeEvent
(QEvent * event
) {
if(_zoomer
&& _zoomer
->isEnabled
() && event
->type
()==QEvent::EnabledChange) {
_zoomer->setEnabled(this->isEnabled());
}
}
private:
};
int main(int argc, char *argv[])
{
Plot* plot = new Plot;
plot->setZoomer(zoomer);
//zoomer->setEnabled(false);
plot->setEnabled(false);
plot->show();
return a.exec();
}
#include <QApplication>
#include <qwt_plot.h>
#include <qwt_plot_zoomer.h>
#include <QEvent>
class Plot: public QwtPlot
{
public:
Plot(QWidget* parent=0):QwtPlot(parent), _zoomer(0)
{
}
void setZoomer(QwtPlotZoomer* zoomer)
{
_zoomer = zoomer;
}
protected:
void changeEvent(QEvent * event)
{
if(_zoomer && _zoomer->isEnabled() && event->type()==QEvent::EnabledChange)
{
_zoomer->setEnabled(this->isEnabled());
}
}
private:
QwtPlotZoomer* _zoomer;
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Plot* plot = new Plot;
QwtPlotZoomer* zoomer = new QwtPlotZoomer(plot->canvas());
plot->setZoomer(zoomer);
//zoomer->setEnabled(false);
plot->setEnabled(false);
plot->show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Because the zoomer/picker is not always enabled in my case,...
Then change things up a little bit.
#include <QApplication>
#include <qwt_plot.h>
#include <qwt_plot_zoomer.h>
#include <QEvent>
{
public:
{
}
{
_zoomer = zoomer;
}
protected:
void changeEvent
(QEvent * event
) {
if(_zoomer
&& _zoomer
->isEnabled
() && event
->type
()==QEvent::EnabledChange) {
_zoomer->setEnabled(this->isEnabled());
}
}
private:
};
int main(int argc, char *argv[])
{
Plot* plot = new Plot;
plot->setZoomer(zoomer);
//zoomer->setEnabled(false);
plot->setEnabled(false);
plot->show();
return a.exec();
}
#include <QApplication>
#include <qwt_plot.h>
#include <qwt_plot_zoomer.h>
#include <QEvent>
class Plot: public QwtPlot
{
public:
Plot(QWidget* parent=0):QwtPlot(parent), _zoomer(0)
{
}
void setZoomer(QwtPlotZoomer* zoomer)
{
_zoomer = zoomer;
}
protected:
void changeEvent(QEvent * event)
{
if(_zoomer && _zoomer->isEnabled() && event->type()==QEvent::EnabledChange)
{
_zoomer->setEnabled(this->isEnabled());
}
}
private:
QwtPlotZoomer* _zoomer;
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Plot* plot = new Plot;
QwtPlotZoomer* zoomer = new QwtPlotZoomer(plot->canvas());
plot->setZoomer(zoomer);
//zoomer->setEnabled(false);
plot->setEnabled(false);
plot->show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Added after 1 29 minutes:
The need to send setZoomer() to Plot coupled with the need to store instances as Plot* rather than QwtPlot* is troubling.
Correct things by auto-detecting an instance of any Zoomer associated with the plot.
When a Zoomer gets constructed, an event (QEvent) is generated. We make use of this fact in our auto-detect scheme.
see code...
note how the subclass, Plot, reimplements eventFilter() .
#include <QApplication>
#include <qwt_plot.h>
#include <qwt_plot_zoomer.h>
#include <qwt_plot_canvas.h>
#include <QEvent>
{
public:
{
}
protected:
{
if(!_zoomer)
initZoomer();
return QwtPlot::eventFilter(obj, ev
);
}
void changeEvent
(QEvent * event
) {
if(_zoomer
&& _zoomer
->isEnabled
() && event
->type
()==QEvent::EnabledChange) {
_zoomer->setEnabled(this->isEnabled());
}
}
private:
void initZoomer()
{
QList<QObject*> L = this->canvas()->findChildren<QObject*>();
for(int i=0; i<L.size(); ++i)
{
_zoomer = dynamic_cast<QwtPlotZoomer*>(L[i]);
if(_zoomer)
break;
}
}
};
int main(int argc, char *argv[])
{
//zoomer->setEnabled(false);
plot->setEnabled(false);
plot->show();
return a.exec();
}
#include <QApplication>
#include <qwt_plot.h>
#include <qwt_plot_zoomer.h>
#include <qwt_plot_canvas.h>
#include <QEvent>
class Plot: public QwtPlot
{
public:
Plot(QWidget* parent=0):QwtPlot(parent), _zoomer(0)
{
}
protected:
bool eventFilter(QObject *obj, QEvent *ev)
{
if(!_zoomer)
initZoomer();
return QwtPlot::eventFilter(obj, ev);
}
void changeEvent(QEvent * event)
{
if(_zoomer && _zoomer->isEnabled() && event->type()==QEvent::EnabledChange)
{
_zoomer->setEnabled(this->isEnabled());
}
}
private:
void initZoomer()
{
QList<QObject*> L = this->canvas()->findChildren<QObject*>();
for(int i=0; i<L.size(); ++i)
{
_zoomer = dynamic_cast<QwtPlotZoomer*>(L[i]);
if(_zoomer)
break;
}
}
QwtPlotZoomer* _zoomer;
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QwtPlot* plot = new Plot;
QwtPlotZoomer* zoomer = new QwtPlotZoomer(plot->canvas());
//zoomer->setEnabled(false);
plot->setEnabled(false);
plot->show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks