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. Change color of circle in QPainter
Qt 6.11 is out! See what's new in the release blog

Change color of circle in QPainter

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 5.0k 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 have the following code:

    QPixmap pm(100,100);
    pm.fill();
    QPainter p(&pm);
    p.setRenderHint(QPainter::Antialiasing, true);
    p.setPen(QPen(Qt::blue,2));
    p.setBrush(QBrush(Qt::green));
    p.drawEllipse(10, 10, 80, 80);
    ui->label.setPixmap(pm);
    

    I would like to add the following if statements:

    if(x==0)
        p.setBrush(QBrush(Qt::white));
    else
        p.setPen(QPen(Qt::black,2));
    

    However, nothing changes and the output keeps telling me: QPaintDevice: Cannot destroy paint device that is being painted.
    Is there any to change the color of the border or inside of the color later on in the code?

    Y 1 Reply Last reply
    0
    • FranckynosF Offline
      FranckynosF Offline
      Franckynos
      wrote on last edited by
      #2

      No you can't change color later but if your funciton is paintEvent you can have variable of color.

      And you need to write p.end(); before ui->label ...

      M 1 Reply Last reply
      0
      • FranckynosF Franckynos

        No you can't change color later but if your funciton is paintEvent you can have variable of color.

        And you need to write p.end(); before ui->label ...

        M Offline
        M Offline
        marlenet15
        wrote on last edited by
        #3

        @Franckynos What do you mean by paintEvent? Can you give me an example?

        1 Reply Last reply
        0
        • FranckynosF Offline
          FranckynosF Offline
          Franckynos
          wrote on last edited by
          #4

          Give me your all function.

          M 1 Reply Last reply
          0
          • FranckynosF Franckynos

            Give me your all function.

            M Offline
            M Offline
            marlenet15
            wrote on last edited by
            #5

            @Franckynos Sorry?

            1 Reply Last reply
            0
            • M marlenet15

              I have the following code:

              QPixmap pm(100,100);
              pm.fill();
              QPainter p(&pm);
              p.setRenderHint(QPainter::Antialiasing, true);
              p.setPen(QPen(Qt::blue,2));
              p.setBrush(QBrush(Qt::green));
              p.drawEllipse(10, 10, 80, 80);
              ui->label.setPixmap(pm);
              

              I would like to add the following if statements:

              if(x==0)
                  p.setBrush(QBrush(Qt::white));
              else
                  p.setPen(QPen(Qt::black,2));
              

              However, nothing changes and the output keeps telling me: QPaintDevice: Cannot destroy paint device that is being painted.
              Is there any to change the color of the border or inside of the color later on in the code?

              Y Offline
              Y Offline
              yoavmil
              wrote on last edited by
              #6

              @marlenet15

              Is there any to change the color of the border or inside of the color later on in the code?

              are you asking if you can change the colors after you called p.drawEllipse()? if thats you question, so you cannot. you cannot change the past.

              this is a valid code:

              QPixmap pm(100,100);
              pm.fill();
              QPainter p(&pm);
              p.setRenderHint(QPainter::Antialiasing, true);
              p.setPen(QPen(Qt::blue,2));
              p.setBrush(QBrush(Qt::green));
              if(x==0)
                  p.setBrush(QBrush(Qt::white));
              else
                  p.setPen(QPen(Qt::black,2));
              p.drawEllipse(10, 10, 80, 80);
              ui->label.setPixmap(pm);
              
              1 Reply Last reply
              2

              • Login

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