Qml Extension and QPainter clipping



  • Hi everybody, I'm creating a Qml extension, but I'm having problems with the QPainter setClipRegion. The clipping is not being antialiased, look:

    !http://img802.imageshack.us/img802/6485/uglyclipping.jpg(ugly clipping)!

    And here is my paint code:

    @void Bola::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
    {
    QRegion regiao(boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height(), QRegion::Ellipse);

    painter->setRenderHints(QPainter::Antialiasing, true);
    
    painter->setClipRegion(regiao);
    painter->drawImage(boundingRect(), QImage("../ParesQml/" + imagem()));
    

    }
    @

    Antialiasing is working for anything outside the clipping, so to workarround this, I'm drawing a big gray border to hide the ugly clipping, look:

    !http://img52.imageshack.us/img52/7313/uglyclippinghack.jpg(hack)!

    Code of the workarround:

    @void Bola::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
    {
    QRegion regiao(boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height(), QRegion::Ellipse);

    QPen pen(m_color, 3);
    painter->setPen(pen);
    
    painter->setRenderHints(QPainter::Antialiasing, true);
    
    painter->setClipRegion(regiao);
    painter->drawImage(boundingRect(), QImage("../ParesQml/" + imagem()));
    
    painter->setClipping(false);
    painter->drawEllipse(boundingRect());
    

    }@

    Does anyone has a better fix for this?


  • Moderators

    You could create now image containing the original masked to be round. This masking should be possible with proper anti aliasing.

    That way you would further avoid having to do the clipping again and again for whenever you need to paint.



  • This seems to be a bug right. Antialiasing should have been working right.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.