PDA

View Full Version : GraphicsView paintEvent question



anafor2004
25th September 2009, 10:02
Dear All , I have created a CustomLabel class which is based QLabel, then I added this label to QGraphicsView via QGraphicsProxyWidget.


CustomLabel *imageItem = new CustomLabel();
imageItem->setSelectionStatus(true);
imageItem->setImagePath("/home/can/workspace/DenemeGraphic/media/home.png");

QGraphicsProxyWidget *pCImageProxyWidgetInstance = new QGraphicsProxyWidget(0, Qt::Window);
pCImageProxyWidgetInstance->setWidget(imageItem);
pCImageProxyWidgetInstance->setCacheMode ( QGraphicsItem::NoCache );
pCImageProxyWidgetInstance->setPos(100,100);
scene->addItem(pCImageProxyWidgetInstance);


In CustomLabel I writed a paintEvent(QPaintEvent *pe) function, the problem is , always it is refreshing , There is a printf() in painEvent and it is continiously printing string.

yogeshgokul
25th September 2009, 10:14
Setting
pCImageProxyWidgetInstance->setCacheMode ( QGraphicsItem::NoCache );
Could cause a continues refreshing. Try other cache modes.
And please show us the paintEvent.

anafor2004
25th September 2009, 10:21
QPixmap CustomLabel::PreparePixmap()
{
QPixmap pixmap;
pixmap.load(m_ImagePath);
pixmap = pixmap.scaled(WIDTH,HEIGHT,Qt::IgnoreAspectRatio,Q t::FastTransformation);
printf("a\n");
return pixmap;
}
void CustomLabel::paintEvent(QPaintEvent *pe)
{
QPainter painter(this);

QPixmap pixmap = PreparePixmap();
setPixmap(pixmap);

if(m_Selected)
{

QPen pen(Qt::red);
pen.setWidth(5);
painter.setPen(pen);
painter.drawPixmap(3,3,pixmap);
painter.drawRect(0,0,width()-1,height()-1);
}
}


it is continously printing "a".

yogeshgokul
25th September 2009, 10:24
What printf doing here ?
Can you please comment the printf statement for a while. use qDebug instead.

anafor2004
25th September 2009, 10:28
I changed it , but it is same, still printing

yogeshgokul
25th September 2009, 10:36
it is continously printing "a".
Where is it printing ?
On my machine its running well, a red colored boundary with a pixmap is displaying with no refreshing problem.