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 do this using QPainter?
Qt 6.11 is out! See what's new in the release blog

How to do this using QPainter?

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

    Hi,

    I have widget filled by green color. Next I draw red ellipse. And I would like to draw transparent rectangle on the ellipse to see green background like this:

    app.png

    I know that I can use QPainterPath to draw what I want: using arc, lines etc.

    But maybe there is a simple solution to use only something like:

    painter->drawRext(100,100,10,10, Qt::transparent);
    

    EDIT

    Of course I know that i can draw green rectangle, but a green background is only example.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      Hi,

      You can substract two paths:

             int radius=100;
             QPainterPath path;
             path.addEllipse(rect().center(),radius,radius);
             QPainterPath recPath;
             int recW=radius/2;
             QRectF rec=path.boundingRect();
             rec.setSize(QSize(recW,recW));
             rec.translate(0,radius-recW/2);
             recPath.addRect(rec);
             path=path.subtracted(recPath);   // substract rect from ellipse
             
             painter.fillPath(path,Qt::red);
      
      1 Reply Last reply
      2

      • Login

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