PDA

View Full Version : how to avoid QCanvasText flickering (Qt336)



oob2
1st September 2006, 20:41
Hi,

I have QCanvas, QCanvasView, QCanvasText objects. I implemented a scrolling text function which will be triggered by a QTimer to move QCanvasText object to left 2 pixels in every 100 ms.

How to avoid it flickering?

Thanks.

wysota
1st September 2006, 21:18
Depends how you implemented it.

oob2
1st September 2006, 22:27
Here is a segment of my code:

m_canvasView = new QCanvasView(this);
m_canvas = new QCanvas();
m_canvasView->setCanvas(m_canvas);
m_canvasText = new QCanvasText(m_canvas);
m_canvasText->setText("whatever");

m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), SLOT(myTick()));
m_timer->start(100);

myTick()
{
m_x -= 2;
m_canvasText->move(m_x, m_y);
}

wysota
1st September 2006, 23:16
Try using QCanvasItem::setAnimated(), QCanvasItem::setVelocity() and QCanvas::setAdvancePeriod() instead of using an own timer.

oob2
5th September 2006, 20:17
Thanks.

I removed my QTimer, override QCanvasText::advance() instead. But, it didn't help.

However, I adjusted the paramenter in setXVelocity() from -2 to -1 and adjusted the parameter in setAdvancedPeriod() from 50 ms to 30 ms; now, it looks much better.

Is it a solution?

wysota
5th September 2006, 20:25
Sure, if you're satisfied with the move. But the effect you had was not flicker (the picture wasn't "blinking"), the move just didn't feel smooth because of too few frames per second.