Create circle using QPainter



  • 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();
    }

  • Moderators

    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



  • Thank you!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.