Ok, it appears that I've got it working the way I want, I had to make a few tweaks to your code, here's what I'm using now:
class ScaleDraw: public QwtDateScaleDraw
{
public:
{
}
void invalidate()
{
invalidateCache();
}
protected:
void drawTick
(QPainter *p,
double val,
double len
) const {
if (mMarker && mMarker->isVisible()) // visibility of this follows that of plot marker
{
p->save();
p->setPen(mMarker->linePen());
double x = mMarker->xValue();
x = scaleMap().transform(x);
p->drawLine(x, 0, x, 10);
p->restore();
}
}
private:
};
class ScaleDraw: public QwtDateScaleDraw
{
public:
ScaleDraw(QwtPlotMarker* marker): m_marker(marker)
{
}
void invalidate()
{
invalidateCache();
}
protected:
void drawTick (QPainter *p, double val, double len) const
{
if (mMarker && mMarker->isVisible()) // visibility of this follows that of plot marker
{
p->save();
p->setPen(mMarker->linePen());
double x = mMarker->xValue();
x = scaleMap().transform(x);
p->drawLine(x, 0, x, 10);
p->restore();
}
QwtScaleDraw::drawTick (p, val, len);
}
private:
QwtPlotMarker* m_marker;
};
To copy to clipboard, switch view to plain text mode
The big change I had to make was where you transform the marker's x value into the pixel's x-coordinate, previously you had:
x
= m_marker
->plot
()->transform
(QwtPlot::xBottom, x
);
p->drawLine(x-1, 0, x-1, 10);
x = m_marker->plot()->transform(QwtPlot::xBottom, x);
p->drawLine(x-1, 0, x-1, 10);
To copy to clipboard, switch view to plain text mode
but that didn't seem to work correctly, the line on the plot wasn't lining up with the line on the scale widget. I played around with it a little, and noticed that the amount of pixels I was off by varied as the number of characters in the scale's leftmost label changed, which makes sense because the lowest valued tick is centered on that label text. So, switching to:
x = scaleMap().transform(x);
p->drawLine(x, 0, x, 10);
x = scaleMap().transform(x);
p->drawLine(x, 0, x, 10);
To copy to clipboard, switch view to plain text mode
seemed to work better, and doesn't require the x-1 you were doing before.
My class that inherits from a QwtPicker emits a custom signal time(double x) whenever the cursor moves over the plot, where x is x value of the picker (in scaled values). I connect that to:
void MainWindow::slotIndex(const double &pos)
{
if (pos == mPrevPos)
{
// no need to do anything if we were triggered because of a y axis move
return;
}
mPrevPos = pos;
if (xLimitMin <= pos && pos <= xLimitMax)
{
marker->setXValue(pos);
marker->show();
markedScaleDraw
* sd
= dynamic_cast<markedScaleDraw
*>
(centralPlot
->axisScaleDraw
(QwtPlot::xBottom));
if (sd)
{
sd->invalidate(); // clear the scale draw's cache
}
} else {
marker->hide();
}
centralPlot->replot();
centralPlot
->axisWidget
(QwtPlot::xBottom)->update
();
// cause scale draw to repaint}
void MainWindow::slotIndex(const double &pos)
{
if (pos == mPrevPos)
{
// no need to do anything if we were triggered because of a y axis move
return;
}
mPrevPos = pos;
if (xLimitMin <= pos && pos <= xLimitMax)
{
marker->setXValue(pos);
marker->show();
markedScaleDraw* sd = dynamic_cast<markedScaleDraw*>(centralPlot->axisScaleDraw(QwtPlot::xBottom));
if (sd)
{
sd->invalidate(); // clear the scale draw's cache
}
} else {
marker->hide();
}
centralPlot->replot();
centralPlot->axisWidget(QwtPlot::xBottom)->update(); // cause scale draw to repaint
}
To copy to clipboard, switch view to plain text mode
Bookmarks