[Qt-interest] Scrolling text problem
Frank Mertens
frank at cyblogic.de
Mon Nov 8 13:33:56 CET 2010
On 11/05/2010 09:22 AM, Marek Bronowicki wrote:
> Hello
>
> I'm making a multimedia player with information scrolls at top and
> bottom of movie.
> when I tried to solve "high CPU usage" I noticed that
> QPainter::drawPixmap is the best for CPU...
> So I'm making a couple of QPixmaps with text, and moving it - but:
> it looks like drawing on the screen is from top to bottom, so moving the
> pixmap from left to right using drawpixmap and paintevent of my widget
> looks like the text is cut in half and one half is running after
> another, and it makes it totally bad for reading.
> Can anyone can guide me what to do to solve it?
>
> for base of my widget I used this article:
> http://www.informit.com/articles/article.aspx?p=1405544
>
> void Ticker::paintEvent(QPaintEvent * /* event */)
> {
> QPainter painter(this);
>
> int textWidth = fontMetrics().width(text());
> if (textWidth< 1)
> return;
> int x = -offset;
> while (x< width()) {
> painter.drawPixmap(x,0,mypixmap)
> x += textWidth;
> }
> }
>
> this is a base paintevent from the article but it's modified to drawpixmap instead of drawtext
>
> I also tried to not make own widget but use qgraphicsview/scene and
> qgraphicspixmapitem, but it's the same. I'm not a mega developer, so I'm
> sure that I didn't used a lot of solutions.
>
My bet: the preparation of the pixmaps is wrong, not the display.
On 4.7 you may also try QStaticText, although pixmaps are a wise choice.
Oh yes, one thing I'm always missing on myself: Pixmaps need to be cleared before painting on it.
For the movie player "QPixmap::fill(Qt::transparent);" should do the job.
Cheers,
Frank.
More information about the Qt-interest-old
mailing list