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. Create circle using QPainter
QtWS25 Last Chance

Create circle using QPainter

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.5k 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.
  • M Offline
    M Offline
    marlenet15
    wrote on last edited by
    #1

    I found the following code which does exactly what I want it to do. However, The QPixmap is making it have a white square background instead of having the same color background as the window which is like gray. Is there anyway to display circle without the white background?

    #include <QtGui>
    
    int main(int argc, char* argv[])
    {
     QApplication app(argc, argv);
     QPixmap pm(100,100);
     pm.fill();
    
     QPainter p(&pm);
     p.setRenderHint(QPainter::Antialiasing, true);
     QPen pen(Qt::blue, 2);
     p.setPen(pen);
     QBrush brush(Qt::green);
     p.setBrush(brush);
     p.drawEllipse(10, 10, 80, 80);
     QLabel l;
     l.setPixmap(pm);
     l.show();
     return app.exec();
    }
    
    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by Eddy
      #2

      the docs tell us white is the default background color

      void QPixmap::fill(const QColor & color = Qt::white)
      Fills the pixmap with the given color.
      

      you could use :
      pm.fill(QColor(255, 0, 0, 0));
      to get a transparant fill

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      1
      • M Offline
        M Offline
        marlenet15
        wrote on last edited by
        #3

        Thank you!!!

        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