void ScopeSetting::paintWidget()
{
qDebug()<<"value ++"<<value;
QPainter painter(ui->widget_3);
QPainterPath path;
int w = 25;
int x = 60;
int y = 30;
for(int i = 0; i < value; i++)
{
path.addRect(x, y, w, 150 - dBValue[i]);
path.addRect(x, y, w, 150);
//字体
QFont font("宋体", 10);
path.addText(x + 4, 150 - dBValue[i] + y - 2, font, QString::number(dBValue[i]));
painter.drawPath(path);
if(dBValue[i] > 120)
{
painter.fillRect(QRect(x, y + 150 - dBValue[i], w, dBValue[i]), QBrush(Qt::red));
}
else
{
painter.fillRect(QRect(x, y + 150 - dBValue[i], w, dBValue[i]), QBrush(QColor(107, 194, 53)));
}
x = x + 70;
}
}
调用 update() 函数、会触发paintWidget() 函数