本文整理汇总了C++中QSize::scaled方法的典型用法代码示例。如果您正苦于以下问题:C++ QSize::scaled方法的具体用法?C++ QSize::scaled怎么用?C++ QSize::scaled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSize
的用法示例。
在下文中一共展示了QSize::scaled方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
void paintEvent(QPaintEvent *)
{
QSize pageSize = m_pageLayout.fullRectPoints().size();
QSizeF scaledSize = pageSize.scaled(width() - 10, height() - 10, Qt::KeepAspectRatio);
QRect pageRect = QRect(QPoint(0,0), scaledSize.toSize());
pageRect.moveCenter(rect().center());
qreal width_factor = scaledSize.width() / pageSize.width();
qreal height_factor = scaledSize.height() / pageSize.height();
QMarginsF margins = m_pageLayout.margins(QPageLayout::Point);
int left = qRound(margins.left() * width_factor);
int top = qRound(margins.top() * height_factor);
int right = qRound(margins.right() * width_factor);
int bottom = qRound(margins.bottom() * height_factor);
QRect marginRect(pageRect.x() + left, pageRect.y() + top,
pageRect.width() - (left + right + 1), pageRect.height() - (top + bottom + 1));
QPainter p(this);
QColor shadow(palette().mid().color());
for (int i=1; i<6; ++i) {
shadow.setAlpha(180-i*30);
QRect offset(pageRect.adjusted(i, i, i, i));
p.setPen(shadow);
p.drawLine(offset.left(), offset.bottom(), offset.right(), offset.bottom());
p.drawLine(offset.right(), offset.top(), offset.right(), offset.bottom()-1);
}
p.fillRect(pageRect, palette().light());
if (marginRect.isValid()) {
p.setPen(QPen(palette().color(QPalette::Dark), 0, Qt::DotLine));
p.drawRect(marginRect);
marginRect.adjust(2, 2, -1, -1);
p.setClipRect(marginRect);
QFont font;
font.setPointSizeF(font.pointSizeF()*0.25);
p.setFont(font);
p.setPen(palette().color(QPalette::Dark));
QString text(QLatin1String("Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi."));
for (int i=0; i<3; ++i)
text += text;
const int spacing = pageRect.width() * 0.1;
const int textWidth = (marginRect.width() - (spacing * (m_pagePreviewColumns-1))) / m_pagePreviewColumns;
const int textHeight = (marginRect.height() - (spacing * (m_pagePreviewRows-1))) / m_pagePreviewRows;
for (int x = 0 ; x < m_pagePreviewColumns; ++x) {
for (int y = 0 ; y < m_pagePreviewRows; ++y) {
QRect textRect(marginRect.left() + x * (textWidth + spacing),
marginRect.top() + y * (textHeight + spacing),
textWidth, textHeight);
p.drawText(textRect, Qt::TextWordWrap|Qt::AlignVCenter, text);
}
}
}
}
示例2: scaleFactor
double ImageWidget::scaleFactor()
{
QSize size = imageSize();
if (size.width() <= 0 || size.height() <= 0) {
return 1;
}
int w = width();
int h = height();
QSize scale = size.scaled(w, h, Qt::KeepAspectRatio);
return ((double)scale.width()) / size.width();
}
示例3: setScaledSize
QJSValue Image::setScaledSize(int w, int h, const QJSValue &scaleMode)
{
QSize newSize(w, h);
if (scaleMode.isNumber()) {
int mode = scaleMode.toInt();
if (mode < 0 || mode > 2) {
qWarning("Invalid scale mode");
} else {
QSize original = m_reader->size();
newSize = original.scaled(newSize, (Qt::AspectRatioMode)mode);
}
}
m_reader->setScaledSize(newSize);
return self();
}