PDA

View Full Version : QGraphicsView: per-item antialiasing specification?



mattc
3rd May 2009, 10:55
Hello,
is it possibile to specify a per-item antialias rendering in a QGraphicsView? As far as I understand QGraphicsView::setRenderHint affects all of the items, but in my application some items would look nicer without aliasing.

Thanks

aamer4yu
3rd May 2009, 12:42
You can use / not use aliasing in the QGraphicsItem::paint itself,, cant you ?

Lykurg
3rd May 2009, 13:24
If you don't want to do all the drawings yourself, subclass you needed item and adjust the flags:


void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setRenderHint(painter->renderHint() /*...*/);
YourBaseClass::paint(painter, option, widget);
}

mattc
3rd May 2009, 13:39
Hello aamer4yu,
somehow such a simple solution didn't cross my mind! Here is the working code:


void MyGraphicItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
painter->setRenderHint(QPainter::Antialiasing);
QGraphicsEllipseItem::paint(painter, option, widget);
painter->setRenderHint(QPainter::Antialiasing, false);
}

Thank you very much.

mattc
3rd May 2009, 13:53
thanks Lykurg,
I've seen your reply after posting. I removed the line restoring the painter state, and changed the first line to preserve existing render hints.


void MyGraphicItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
painter->setRenderHints(painter->renderHints() | QPainter::Antialiasing);
QGraphicsEllipseItem::paint(painter, option, widget);
}

Btw, browsing the docs I found some inconsistency about the render hints functions. From QPainter:


The renderHints() function returns a flag that specifies the rendering hints that are set for this painter. Use the setRenderHint() function to set or clear the currently set RenderHints

so, what is setRenderHint*s*() supposed to do? Also, no "renderHint()" in QPainter.

Lykurg
3rd May 2009, 14:30
so, what is setRenderHint*s*() supposed to do? Also, no "renderHint()" in QPainter.
Yeah, I was mixing up some things. It's:
QPainter::setRenderHint ( RenderHint hint, bool on = true );
or
QPainter::setRenderHints ( RenderHints hints, bool on = true );
with hints g.e. "QPainter::Antialiasing|QPainter::TextAntialiasing".