View Full Version : Refresh + QGraphicItem + drawText

18th August 2009, 07:53
Hey @all,

for my Project I decided to subclass QGraphicItem and reimplement the paint function.

void MyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
// Draw the pixmap

// Draw the item text
painter->drawText(QRectF(-_pixmap.width(), 5, _pixmap.width(), 25), Qt::AlignHCenter, "Demotext");

From now, when i move the drawn item, the text aren't repainted / updated. When i move the graphics item fast over the graphics scene, then there are only black fragments from the text, but no "Demotext".

What I'm doing wrong?

Best Regards

18th August 2009, 08:01
i think the update() is calling before the paint() completes drawText() ..
use qApp->processEvents(); in the paint() ..
this paint i think we cant use QThreads() any way u try any other option like mandelbolt example ... http://doc.trolltech.com/4.3/threads-mandelbrot.html

18th August 2009, 08:32
I tried also

at the end of the function, but nothing was changed.

I've attached an example to show how it looks

Best Regards

18th August 2009, 08:42
exactly the next update() is called the paint::update() before drawText() ...

is it possible to port a new QEventLoop() in the code .. ? or QThread() .. this seperate event loop should emit the signal to update() when user moves the cursor ..
did u see the mandelbrot example ..

18th August 2009, 08:55
I think i found the solution, the problem was within the boundingRect() function, where the text wasn't included.

Best Regards