PDA

View Full Version : QwtPlotMarker On the Center of the Plot



ken123
28th November 2011, 16:14
I am trying to have to two labels in the middle of the QwtPlot.
ie: plot
|--------------------------------------|
| |
| top center label |
| |
| label 2 |
| |
|--------------------------------------|
How can I do that? Thanks.

Uwe
29th November 2011, 07:48
Implement a new type of plot item ( derive from QwtPlotItem ). In YourItem::draw use QPainter ::drawText centered to the canvasRect.

Uwe

ken123
29th November 2011, 15:49
I am a bit confused. When do I call this new myItem::draw method or how do I call this method, like override a new drawCanvas method for myQwtPlot? Thanks.

Uwe
1st December 2011, 06:29
Something like this:


class TextItem: public QwtPlotItem
{
public:
void setText( const QString &text )
{
m_text = text;
}

virtual void draw( QPainter *painter,
const QwtScaleMap &, const QwtScaleMap &,
const QRectF &canvasRect ) const
{
painter->drawText( canvasRect, Qt::AlignCenter, m_text );
}

private:
QString m_text;
};

Attach this item to your plot like a curve and the draw method will be part of the plot image composition.

Uwe