Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Create circle using QPainter

    General and Desktop
    2
    3
    1025
    Loading More Posts
    • 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
      marlenet15 last edited by

      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 Reply Quote 0
      • E
        Eddy last edited by Eddy

        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 Reply Quote 1
        • M
          marlenet15 last edited by

          Thank you!!!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post