【发布时间】:2017-12-23 03:15:46
【问题描述】:
我正在自定义小部件中绘画以匹配“Google 风格”卡片。我的大部分尺寸和字体都是正确的,但是在绘制图像时它总是被拉伸。这是参考图像和相关代码。我想保持图像的默认纵横比。
图片:
QRect topPortion = QRect(QPoint(0, 0), QSize(width(), (height()/4)*3));
QPainterPath backgroundPath;
backgroundPath.addRect(topPortion);
QPainterPath bottom = getCornerPath().subtracted(backgroundPath);
QRect bottomRect = QRegion(rect()).subtracted(QRegion(topPortion)).boundingRect();
painter.fillPath(getCornerPath(), m_bColor);
painter.fillPath(bottom, m_fColor);
painter.drawPixmap(topPortion, m_image.scaled(topPortion.size(), Qt::KeepAspectRatio, Qt::FastTransformation));//Issue
painter.setPen(QPen(QColor(50, 50, 50)));
painter.setFont(titleFont);
painter.drawText(QPointF(12, topPortion.height()+((bottomRect.height()-fontHeight)/2)+QFontMetrics(titleFont).ascent()), "Add Record");
painter.setFont(subtitleText);
painter.drawText(QPointF(12, topPortion.height()+((bottomRect.height()-fontHeight)/2)+fontHeight), "Add Record");
【问题讨论】: