win32 {}
unix {}
//Qt5可以直接用 linux{} Qt4切记需要用 unix:!maxc{}
unix:!maxc{}
linux {}
maxc {}
android {}
wasm {}
//表示64位平台
contains(QT_ARCH, x86_64) {}
//表示arm平台
contains(QT_ARCH, arm) || contains(QT_ARCH, arm64) {}
//万能办法直接切换到套件打印下 QT_ARCH 看下什么字符
message($QT_ARCH)
//传入图片尺寸和窗体区域及边框大小返回居中区域
static QRect getCenterRect(const QSize &imageSize, const QRect &widgetRect, int borderWidth = 2, bool alwaysScale = true)
{
QSize newSize = imageSize;
QSize widgetSize = widgetRect.size() - QSize(borderWidth * 2, borderWidth * 2);
//alwaysScale = false 表示只有尺寸超过窗体尺寸才缩放否则就原图尺寸
if (alwaysScale) {
newSize.scale(widgetSize, Qt::KeepAspectRatio);
} else if (newSize.width() > widgetSize.width() || newSize.height() > widgetSize.height()) {
newSize.scale(widgetSize, Qt::KeepAspectRatio);
}
int x = widgetRect.center().x() - newSize.width() / 2;
int y = widgetRect.center().y() - newSize.height() / 2;
return QRect(x, y, newSize.width(), newSize.height());
}
//传入图片尺寸和窗体尺寸及缩放策略返回合适尺寸的图片
static void getScaledImage(QImage &image, const QSize &widgetSize, bool alwaysScale = false, bool fast = true)
{
//alwaysScale = false 表示只有尺寸超过窗体尺寸才缩放否则就原图尺寸
if (alwaysScale) {
image = image.scaled(widgetSize, Qt::KeepAspectRatio, fast ? Qt::FastTransformation : Qt::SmoothTransformation);
} else if (image.width() > widgetSize.width() || image.height() > widgetSize.height()) {
image = image.scaled(widgetSize, Qt::KeepAspectRatio, fast ? Qt::FastTransformation : Qt::SmoothTransformation);
}
}
国内站点:https://gitee.com/feiyangqingyun
国际站点:https://github.com/feiyangqingyun
| 留言与评论(共有 0 条评论) “” |