Consider the following code:
QwtPlotClient::QwtPlotClient(QWidget* parent)
: QDialog(parent),
m_plot(new QwtPlot()),
m_marker(new QwtPlotMarker())
{
m_ui.setupUi(this);
m_ui.plotFrame->layout()->addWidget(m_plot);
m_plot->setCanvas(new QwtPlotOpenGLCanvas());
m_marker->setLineStyle(QwtPlotMarker::VLine);
m_marker->setLabelAlignment(Qt::AlignBottom | Qt::AlignRight);
m_marker->setLinePen(QPen(QColor(0, 0, 255), 0, Qt::DashLine));
m_marker->setValue(15.0, 0.0);
m_marker->setLabel(QString("15.0"));
m_marker->attach(m_plot);
const QVector<QPointF> curvePoints{{10, 10}, {20, 0}, {30, 20} , {40, -10} , {50, -5} };
auto* curve = new QwtPlotCurve();
curve->setSamples(curvePoints);
curve->setPen(Qt::red);
curve->attach(m_plot);
auto* buttonLayout = new QHBoxLayout;
m_ui.verticalLayout->addLayout(buttonLayout);
auto button = new QPushButton("<-");
connect(button, &QPushButton::clicked, this, [this]()
{
m_plot->setAxisScale(QwtPlot::xBottom, 20, 60);
m_plot->replot();
});
buttonLayout->addWidget(button);
button = new QPushButton("->");
connect(button, &QPushButton::clicked, this, [this]()
{
m_plot->setAxisScale(QwtPlot::xBottom, 10, 50);
m_plot->replot();
});
buttonLayout->addWidget(button);
buttonLayout->addSpacerItem(new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Fixed));
}
It creates a dialog with a QwtPlot that contains a red colored curve and a blue colored marker. A button labeled "<-" shifts the x axes 10 to the left, so that the marker is outside of the visible canvas. A button labeled "->" shifts the x axes back to its original range.
When I click the "<-" button the curve's color changes to blue - or to be more precise: to the color of the marker. When I change the color of the marker, the curve will take that color instead. The curve's color changes back to red when I click on the "->" button.
The problem does not occur when I do not use an OpenGL canvas, but a regular canvas. I am not sure how much this bug is part of Qwt itself and how much Qt itself is to blame for rendering the OpenGL part incorrectly. We are using Qt 5.14 and Qwt 6.2.0.
Anonymous
I tried the attached code with the qwt-6.3 branch with Qt 5.15.9 on my Linux box. In this combination I can't see the issue. Please try the code in your environment with the same Qt/Qwt versions.