Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QGraphicsPixmapItem QGraphicsRotation NO ANTIALIASING!



  • Hello,

    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 @ painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing); @ in the paint method, and then call QGraphicsPixmapItem::paint(painter, option, widget), but I still did not get any antialiasing.

    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? Does it for example override your renderhints? Is it set to use device coordinate caching?



  • "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:

    @
    void QGraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    QWidget *widget)
    {
    Q_D(QGraphicsPixmapItem);
    Q_UNUSED(widget);

    painter->setRenderHint(QPainter::SmoothPixmapTransform,
                           (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":http://doc.qt.nokia.com/latest/qgraphicspixmapitem.html#setTransformationMode.

    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.

    Regards,
    Bill



  • Well to step into the Qt code in the debugger you need a debug build of Qt. You can open the source in your ide though.



  • I think my Qt is compiled with debug option, though I have to triple check this.

    Now, i am still stuck with pixmap items being grouped in a pixmap group, the rendering is still not antialiased for those.
    Have to check this now.

    Thank you ZapB



  • You're welcome. Feel free to come back with more questions if you can't resolve it. Code snippets (or even better compilable examples) are always useful.



  • I couldn't find a simple solution to apply a QGraphicsRotation directly to a QGraphicsItemGroup and have my items been displayed with antialiasing, so I simply apply the QGraphicsRotation to each items included in my group to have something decent.
    Thank you,

    Bill


Log in to reply