PDA

View Full Version : Changing renderHints of QGraphicsView after object creation



olidem
2nd March 2009, 10:06
Hi,

I am new to QT programming (but I really like it :-)) and here is an issue I do not know how to solve:

I would like to be able to switch the renderHint QPainter::SmotthPixmapTransform on and off dynamically.

My custom QGraphicsItem looks like



class MyItem : public QGraphicsItem
{
public:
MyItem()
{
QGraphicsLineItem * top = new QGraphicsLineItem(...,this);
QGraphicsLineItem * left = new QGraphicsLineItem(...,this);
QGraphicsPixmapItem * pix = new QGraphicsPixmapItem(...,this);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
if(mouseaction_going_on)
painter->setRenderHint(QPainter::SmoothPixmapTransform, false);
else
painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
}
}

But in practice, nothing happens, the rendering is performed with exactly those renderHints that have been specified at creation time of the QGraphicsView.

What about the painter->save() and restore() functions? Might they help me?

By the way, at whcih stage of the painting procedure is the painting of the child items of MyItem perfomed? Maybe the painting of them is already done when it comes to my setRenderHints()-calls.

Thank you very much in advance for your great support!!!

Best Regards,
Oliver

olidem
2nd March 2009, 20:32
Solution

Hi,
I solved the problem on my own. For those of you who are interested:

instead of trying to configure the painter in my custom item class,
I just call before my operation


MyItem::mousePressEvent(...){
this->scene()->views().first()->setRenderHint(QPainter::SmoothPixmapTransform, false);
}


and after it



MyItem::mouseReleaseEvent(...){
this->scene()->views().first()->setRenderHint(QPainter::SmoothPixmapTransform, true);
}


And it works!
Nice!
I really start liking Qt!
Regards,
Olli