八
7
Plus Your Qt
八
7
Searching around, there’s no good way for a font filter when using QFont. Since QPainter still usable for us, we could use QPainter to draw text looks like glow.
Glow text can be treated as “text beyond text”, which means:
More layers, more glow we look like. The code can be seems like below:
void GlowTicker::paintEvent(QPaintEvent *)
{
QPainter painter(this);painter.setOpacity(0.5);
painter.setPen(_glowColor);
painter.drawText(QRect(QPoint(1 – _offset, 2), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(3 – _offset, 2), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(2 – _offset, 1), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(2 – _offset, 3), textSize()), Qt::TextSingleLine, _text);int w = preferedWidth();
painter.drawText(QRect(QPoint(1 + w – _offset, 2), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(3 + w – _offset, 2), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(2 + w – _offset, 1), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(2 + w – _offset, 3), textSize()), Qt::TextSingleLine, _text);painter.setOpacity(1);
painter.setPen(_textColor);
painter.drawText(QRect(QPoint(2 – _offset, 2), textSize()), Qt::TextSingleLine, _text);
painter.drawText(QRect(QPoint(2 + w – _offset, 2), textSize()), Qt::TextSingleLine, _text);
}
For the layers, we need them transparent or it will influence the main layer.
Well, last show:
<a href="http://qtplus.info/wp-content/uploads/2011/08/glow-text1.png"><img class="alignnone size-full wp-image-74" title="glow text" src="http://qtplus.info/wp-content/uploads/2011/08/glow-text1.png" alt="" width="234" height="64" /></a>