Originally Posted by
Maximus2
For the QwtPlotMarker, since the position is always in middle of the graph canvas, I could use a custom QLabel that sit there and doesn't move..
Sure, but for this particular use case this doesn't make much sense as all what needs to be done is a plot item that draws a vertical line in the center of the canvas:
{
public:
const QRectF &canvasRect
) const {
painter->setPen( ... );
painter->drawLine( canvasRect.center.x(), canvasRect.top(), canvasRect.center.x(), canvasRect.bottom() );
}
};
class MarkerItem: public QwtPlotItem
{
public:
virtual void draw( QPainter *painter,
const QwtScaleMap &, const QwtScaleMap &,
const QRectF &canvasRect ) const
{
painter->setPen( ... );
painter->drawLine( canvasRect.center.x(), canvasRect.top(), canvasRect.center.x(), canvasRect.bottom() );
}
};
To copy to clipboard, switch view to plain text mode
Using widget overlays makes sense when the content of the overlay is moving fast and you want to avoid replots.
But before using just any widget for such a use case you should have a look at QwtWidgetOverlay, what is tailored for this situation. In opposite to regular widgets it calculates a widget mask to avoid full repaints ( = flushing the backing store ) of the plot canvas, when its content changes. In a powerful environment you won't see the difference, but f.e. when running the itemeditor remote X11 ( or on slow embedded devices with QWS ) example you will see a major difference.
Uwe
Bookmarks