Trying to set color
Unsolved
General and Desktop
-
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:
this->setStyleSheet("background-color:black;"); //this->setBackgroundRole(QPalette::Foreground); QPainter p(this); QPen pen; pen.setWidth(10); pen.setColor(Qt::red); p.setPen(pen); p.setRenderHint(QPainter::Antialiasing); 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)+" %");
-
Hi,
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. -
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); this->setPalette(pal);
Instead of using stylesheet for filling background i used this type to fill my widget background.