16,787
社区成员




QString CMainWidget::calcValue(int nValue,int nTotal)
{
QString strStyle = "";
int value1 = nTotal * 0.3 + 0.5;
if (nValue > value1)
{
QString str1;
QString str2;
float scale1 = (float)value1 / (float)nValue;
float scale2 = scale1 + 0.000004;
str1 = str1.setNum(scale1,'f',6);
str2 = str2.setNum(scale2,'f',6);
if (nValue > (value1 + value2))
{
QString str3;
QString str4;
float scale3 = 2.0 * scale1;
float scale4 = scale3 + 0.000004;
str3 = str3.setNum(scale3,'f',6);
str4 = str4.setNum(scale4,'f',6);
qDebug() << str3 << str4;
strStyle = QString("qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, \
stop:0 rgba(255, 0, 0, 255), stop:%1 rgba(255, 0, 0, 255), \
stop:%2 rgba(255, 255, 0, 255), stop:%3 rgba(255, 255, 0, 255) \
stop:%4 rgba(0, 0, 255, 255), stop:1 rgba(0, 0, 255, 255))")
.arg(str1)
.arg(str2)
.arg(str3)
.arg(str4);
}
else
{
strStyle = QString("qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 0, 0, 255), stop:%1 rgba(255, 0, 0, 255), stop:%2 rgba(255, 255, 0, 255), stop:1 rgba(255, 255, 0, 255))")
.arg(str1)
.arg(str2);
}
}
else
{
strStyle = "rgba(255, 0, 0, 255)";
}
return strStyle;
}
void CMainWidget::slt_valueChanged(int value)
{
m_progressbar->setValue(value);
m_progressbar->setStyleSheet(QString(""
" QProgressBar {"
" border: 2px solid grey;"
" border-radius: 5px;"
""
"}"
"QProgressBar::chunk {"
" background-color: "
"%1;"
"}").arg(calcValue(value,m_progressbar->maximum())));
}
ui->processBar->setStyleSheet("QProgressBar::chunk { background-color: rgb(255, 0, 0) }");