does anyone know how to change the box and text color of the QwtPlotZoomer object in C++? My plot canvas background is black and the box that is drawn when dragging the mouse is also black, making it difficult to see the zoom selection.
Thanks!
Use setRubberBandPen() to pass the QPen() that has the color of the edge of the rectangle.
Example:
#include <QApplication>
#include <QMainWindow>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_zoomer.h>
int main( int argc, char **argv )
{
QApplication a( argc, argv );
a.setStyleSheet("QwtPlotCanvas { background: black; } ");
QwtPlot * plot = new QwtPlot();
plot->setAxisAutoScale(QwtPlot::xBottom);
plot->setAxisAutoScale(QwtPlot::yLeft);
QwtPlotZoomer *zoomer;
zoomer = new QwtPlotZoomer( QwtPlot::xBottom, QwtPlot::yLeft, plot->canvas() );
zoomer->setRubberBandPen(QPen(Qt::white));
// create data
std::vector<double> x(100);
std::vector<double> y1(x.size());
for (size_t i = 0; i< x.size(); ++i) { x[i] = int(i)-50; }
for (size_t i = 0; i< y1.size(); ++i) {
y1[i] = i*i;
}
// first curve
QwtPlotCurve *curve = new QwtPlotCurve();
curve->setPen(Qt::white);
curve->setRawSamples(&x[0], &y1[0], x.size());
curve->attach( plot );
plot->replot();
QMainWindow window;
window.setCentralWidget(plot);
window.resize(800, 600);
window.show();
return a.exec();
}