//绘制准备工作,启用反锯齿,平移坐标轴中心,等比例缩放标签:QT,200.0,QPainter,font,绘制,side,painter From: https://blog.51cto.com/u_15515702/5789375
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
if (showRect) {
//绘制矩形区域
painter.setPen(Qt::NoPen);
painter.setBrush(bgColor);
painter.drawRoundedRect(this->rect(), 5, 5);
//绘制文字
if (!text.isEmpty()) {
QFont font;
font.setPixelSize(side - 20);
painter.setFont(font);
painter.setPen(textColor);
painter.drawText(this->rect(), Qt::AlignCenter, text);
}
} else {
painter.translate(width / 2, height / 2);
painter.scale(side / 200.0, side / 200.0);
//绘制外边框
drawBorderOut(&painter);
//绘制内边框
drawBorderIn(&painter);
//绘制内部指示颜色
drawBg(&painter);
//绘制居中文字
drawText(&painter);
//绘制遮罩层
drawOverlay(&painter);