Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qml Extension and QPainter clipping
Forum Updated to NodeBB v4.3 + New Features

Qml Extension and QPainter clipping

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    puelocesar
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kamalakshantv
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved