[Qt-interest] Scrolling text problem

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Mon Nov 8 15:50:59 CET 2010


Hi Marek, 

If you want the text to appear like an <anchor> tag in IE browsers, you need
to get rid of the while loop in your paintEvent, and only draw the pixmap in
one spot each time.  Then use a timer to call update() periodically.  In
your class, something like: 


int nextX;
void textChangedSlot { pixmap = /* new text */;  nextX = -pixmap.width(); }
void paintEvent {
	QPainter painter(this);

	++nextX; 
	if (nextX > contentRect().width())
		nextX = -pixmap.width();

	painter.drawPixmap(nextX,0,mypixmap);
}

Adjusting the timer duration will alter the speed of the animation.  If you
also want the text to wrap, then you will sometimes need to draw the two
portions of the pixmap separately.  

Hope that helps,

Tony

> -----Original Message-----
> Sent: Friday, 5 November 2010 19:22
> 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.
> 
> Regards,
> Marek Bronowicki





More information about the Qt-interest-old mailing list