QGraphicsPixmapItem QGraphicsRotation NO ANTIALIASING!
I am trying to display a simple pixmap item (based on a PNG file) iniside my scene and apply a 3D rotation to it using QGraphicsRotation (rotation around the Y axis). And I would like to get the pixmap drawn with antialiasing.
I have to set the RenderHints to (QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing); in my QGraphicsView constructor, but the drawing of the QGraphicsPixmapItem was still without antialiasing.
So I derived my own QGraphicsPixmapItem class, to be able to overload the paint method. I added a
I have the same isssue either on Windows XP, or under Linux X11.
In the paint method of my derived class, if I call paint->drawPixmap(…) then the pixmap is drawn correctly, I mean with antialiasing.
Can somebody explain to me why is there no antialiasing in my previous described cases? Thank you!
Edit: adapted text a bit to fix rendering; Andre
“Well, what does QGraphicsPixmapItem::paint() do that is different to what you do?”
-> I don’t know, but apprently it does not change my renderhints apparently.
“Is it set to use device coordinate caching?”
-> I don’t know, I just tried to set the caching mode myselft and tried the three options, none of them changed anything.
Don’t be afraid to look into the Qt source – it won’t bite you ;-). A 2 minute search of the Qt source code reveals this:
- QWidget *widget)
- (d->transformationMode == Qt::SmoothTransformation));
- painter->drawPixmap(d->offset, d->pixmap);
- if (option->state & QStyle::State_Selected)
- qt_graphicsItem_highlightSelected(this, painter, option);
So the paint function does set a render hint. Notably the QPainter::SmoothPixmapTransform renderhint. So it sets this to true iff
- d->transformationMode == Qt::SmoothTransformation
So how do we get this to evaluate to true? A quick look at the docs shows me this function [doc.qt.nokia.com].
I suggest you call this function and set the transformation mode to true once you have created your item. Then you should get anti-aliased drawing (unless you override it with something else in your derived paint event of course) ;-)
The problem I actually have is debugging under Linux, when I press F11 on the call to the paint line, IT SIMPLY WON’T DISPLAY ANY SOURCE CODE AT ALL. This GDB thing is driving me crazy, I tried days and days to get the source code to get displayed but it simply wouldn’t.
Anyway I tried on PC, and here I can access the source code alas.
So I set the Qt::SmoothTransformation mode as you mentionned and IT IS ACTUALLY WORKING Now!
I thank you for your answer to my question. We can now close this thread.
Thank you ZapB.