PDA

View Full Version : Add outline/shadow to QwtText



novackb
8th July 2015, 21:58
I have a QwtPlotMarker that I configure using QwtFont and QwtText to get the font/color that I desire. The data is being displayed in image mode using a QwtPlotSpectrogram. The problem is the marker text is easy/hard to read depending on the current color behind it. Just changing the font color doesn't help because the image color behind it is constantly changing.

I'd like to add a single-pixel border just around the text (not a box) to help the text 'pop'. I came across the QGraphicsDropShadowEffect class in Qt which might work, but QwtText doesn't seem to have that capability natively.

Here's my current code to create the QwtPlotMarker. Nothing fancy, but in case it helps....


QwtPlotMarker selectedPoint = new QwtPlotMarker();
QwtText labelText("");
labelText.setColor(Qt::black);
QFont labelFont("Times", 12, QFont::Black);
labelText.setFont(labelFont);
selectedPoint->setLabel(labelText);
selectedPoint->setLabelAlignment(Qt::AlignTop);
selectedPoint->attach(this);

I then update the labelText as new data is received via external message.

Any ideas or suggestions to point me in the right direction are appreciated.
Bryan

Uwe
9th July 2015, 07:48
One option might be to add a semitransparent white background - like it is done for tracker text in the spectrogram example.

Otherwise you could try to overload QwtPlotMarker::drawLabel somehow like this:


virtual void YourMarker::drawLabel( QPainter *painter, const QRectF &canvasRect, const QPointF &pos ) const
{
painter->save();
painter->setPen( Qt::black );
QwtPlotMarker::drawLabel( painter, canvasRect, pos + QPointF( -1, 1 ) );
painter->restore();

QwtPlotMarker::drawLabel( painter, canvasRect, pos );
}Uwe