PDA

View Full Version : Is there a way to draw margin a QwtText around?



KoVi
31st October 2014, 09:17
I would like to draw margin a QwtText around, between the text and the border line.
I want to use it in QwtPlotMarker.

Please help me. Thanks!

Uwe
1st November 2014, 15:55
Are you talking about shifting the position of a marker label, when it comes to close to the canvas border ?

Uwe

KoVi
3rd November 2014, 10:10
Hi Uwe!

I want to initialise a QwtPlotMarker by a QwtText wich has border ( the border pen has been set).
I would like to see a margin between the text and the borderline when I shows this QwtPlotMarker. But now the border are close to the border.
Is there any way to draw margin in a QwtText?



QwtPlotMarker* m_pDescription;
QwtText m_descriptionText;
...
m_pDescription = new QwtPlotMarker();
m_pDescription->attach( ui->pltCurve ); // This is the QwtPlot
...
QPen tmpPen = m_descriptionText.borderPen();
tmpPen.setStyle( Qt::SolidLine );
tmpPen.setWidth( 1 );
m_descriptionText.setBorderPen(tmpPen);
...
m_pDescription->setValue( pos ); // Where pos is a QPosF
m_descriptionText.setText( txt ); // Where txt is a QString
m_pDescription->setLabel( m_descriptionText );
m_pDescription->show();

m_pDescription->setLabel( m_descriptionText );


Sorry, but my english not very good.
Thanks for your help!

KoVi

Uwe
7th November 2014, 07:05
In general a QwtText is painted using QwtText::drawText( QPainter *, const QRectF &). So what you can do is to overload QwtPlotMarker::drawLabel() calculating a different ( = larger ) rectangle.

Uwe

Sintegrial
25th May 2016, 10:04
Hi!

Is it possible to add a custom margin between QwtText's inner border and the text itself?
Otherwise it looks quite ugly when borderPen and borderRadius are defined.

I mean something like QwtText::setInnerMargin(2) for example.
Thanks!

Uwe
31st May 2016, 09:07
All you can do is the derive from QwtTextEngine overloading QwtTextEngine::textMargins, register it with QwtText::setTextEngine and use this special engine for the texts, where you need the extra margins.

Of course this is only a workaround and there should be something like QwtText::setInnerMargin().

Uwe