1.图片资源关联设备缩放比
QPixmap Pixmg::getPixmap(const QString name, const QSize size)
{
const QIcon &icon = QIcon(name);
const qreal ratio = devicePixelRatioF();
QPixmap pixmap = icon.pixmap(size * ratio).scaled(size * ratio, Qt::KeepAspectRatio, Qt::SmoothTransformation);
pixmap.setDevicePixelRatio(ratio);
return pixmap;
}
2.绘制时钟
图片资源的宽,高
static const QSize clockSize = QSize(224, 224);
static const QSize pointSize = QSize(145, 15);
void Pixmg::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
QPixmap pix;
QDateTime datetime(QDateTime::currentDateTimeUtc());
const QTime time(datetime.time());
QPainter painter(this);
painter.setRenderHints(QPainter::**HighQualityAntialiasing** | QPainter::SmoothPixmapTransform);
// draw plate
painter.save();
pix = getPixmap(":/images/clock_black.svg", clockSize);
painter.translate(width() / 2.