Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to change color in QPainter::CompositionMode_DestinationIn?
Forum Updated to NodeBB v4.3 + New Features

How to change color in QPainter::CompositionMode_DestinationIn?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 198 Views
  • 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.
  • Q Offline
    Q Offline
    qwe3
    wrote on last edited by qwe3
    #1

    Hi,

    I have someWidget class ( inherits QWidget ) and paintEvent() on it.

    void someWidget::paintEvent(QPaintEvent *)
    {
        QPainter painter(this);
        painter.setRenderHints(QPainter::Antialiasing);
        painter.setPen(Qt::NoPen);
    
        painter.fillRect(0, 0, width(), height(), Qt::white);
    
    
        int radius = 100;
        painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
    
        QRadialGradient radialGrad(QPoint(200,200), radius);
        radialGrad.setColorAt(0, QColor(255, 0, 0, 0));
        radialGrad.setColorAt(1, QColor(255, 0, 0, 255));
        painter.setBrush(radialGrad);
    
        painter.drawEllipse(QPoint(200,200), radius, radius);
    }
    

    And I would like to have red ellipse. Now I have black ellipse.

    result.png

    I tried to set:

        radialGrad.setColorAt(0, QColor(255, 0, 0, 0));
        radialGrad.setColorAt(1, QColor(255, 0, 0, 255));
    

    To other colors: blue, green, but result is the same - black ellipse. So how can I get the red one?

    EDIT:
    Even simpler code:

    void someWidget::paintEvent(QPaintEvent *)
    {
        QPainter painter(this);
        painter.setRenderHints(QPainter::Antialiasing);
        painter.setPen(Qt::NoPen);
    
        painter.fillRect(0, 0, width(), height(), Qt::white);
    
        int radius = 100;
        painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
    
        painter.setBrush(QColor(255,0,0,200));
    
        painter.drawEllipse(QPoint(200,200), radius, radius);
    }
    
    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