QwtPlotZoomer 矩形颜色

QwtPlotZoomer Rectangle Color

有谁知道如何在 C++ 中更改 QwtPlotZoomer 对象的框和文本颜色?我的plotcanvas背景是黑色的,拖动鼠标画出的框也是黑色的,很难看清缩放选择。

谢谢!

使用setRubberBandPen()传递具有矩形边缘颜色的QPen()。

示例:

#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();
}