Important: Please read the Qt Code of Conduct -

Trying to set color

  • I am trying to draw an arc when we slide the slider i will draw the arc with Red color . Now when i set the backgroud color of the ui to black the arc which i draw is not visible. My code:

    QPainter p(this);
    QPen pen;
    QRectF rectangle(ui->LB_Progress->x()-20, ui->LB_Progress->y()-20, 80.0, 80.0);
    //to understand these magic numbers, look drawArc method in Qt doc
     int startAngle = -(270 * 16);
     int spanAngle =-(progress * 360 * 16);
    p.drawArc(rectangle, startAngle, spanAngle);
    p.drawText(rectangle,Qt::AlignCenter,QString::number(progress*100)+" %");

  • Lifetime Qt Champion


    Why are you using a stylesheet since you do the painting yourself ?
    Start by filling the widget in black and then paint the rest over it.

  • @SGaist said in Trying to set color:

    how to do that sir,
    I am not getting your point

  • @SGaist

    Sir i used something like this and it worked

     QPalette pal(this->palette());
     QColor color(Qt::black);
     pal.setColor (QPalette::Background, color);
     this->setAutoFillBackground (true);

    Instead of using stylesheet for filling background i used this type to fill my widget background.

  • Lifetime Qt Champion

    Since you already have a paintEvent,
    all you need to paint it black is
    p.drawRect( rect () );

Log in to reply