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
Forum Updated to NodeBB v4.3 + New Features

Create circle using QPainter

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.5k 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.
  • M Offline
    M Offline
    marlenet15
    wrote on 27 Oct 2015, 17:20 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
    • E Offline
      E Offline
      Eddy
      wrote on 27 Oct 2015, 17:37 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 27 Oct 2015, 17:42 last edited by
        #3

        Thank you!!!

        1 Reply Last reply
        0

        1/3

        27 Oct 2015, 17:20

        • Login

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