Important: Please read the Qt Code of Conduct -

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);
     QPainter p(&pm);
     p.setRenderHint(QPainter::Antialiasing, true);
     QPen pen(Qt::blue, 2);
     QBrush brush(Qt::green);
     p.drawEllipse(10, 10, 80, 80);
     QLabel l;
     return app.exec();

  • 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