[英]Low quality QPixmap in Windows
我正在通过 QSqlTableModel 将 QPixmap 上传到 QTableView。 在 Linux 上,图像以正常质量显示,但在 Windows 上,图像质量非常低。 有没有可能以某种方式修复它?
Qt 6
我的代码片段:
SqlTableModel::SqlTableModel(QObject *parent, QSqlDatabase db)
: QSqlTableModel(parent, db)
{
int iconheight = QFontMetrics(QApplication::font()).height() * 2 - 4;
m_IconSize = QSize(iconheight, iconheight);
/*...*/
m_ActoinMMIcon = QPixmap(":/resources/img/many_many.svg", "SVG").
scaled(m_IconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
/*... etc ...*/
}
QVariant SqlTableModel::data(const QModelIndex &index, int role) const
{
if(role == Qt::BackgroundRole && isDirty(index)) return QBrush(QColor(Qt::yellow));
auto field = record().field(index.column());
auto tablename = field.tableName();
auto fieldname = field.name();
/*...*/
// TABL_TASKS
if(tablename == TABL_TASKS)
{
if(fieldname == COL_TASKACTTYPE)
{
if(role == Qt::DisplayRole) return QString();
else if(role == Qt::DecorationRole)
{
auto value = QSqlTableModel::data(index, Qt::DisplayRole).toInt();
if(value == Action::ManyFromMany) return m_ActoinMMIcon;
else if(value == Action::OneFromMany) return m_ActoinOMIcon;
else if(value == Action::AsValue) return m_ActoinValueIcon;
else return m_ErrorIcon;
}
else if(role == Qt::SizeHintRole) return m_IconSize;
}
/*...*/
}
/*...*/
return QSqlTableModel::data(index, role);
}
在main()
function 中的 Qt 6 之前,在 app.exec app.exec()
调用之前,我们习惯于设置这些:
// Unfortunately no longer working with Qt 6.
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling)
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
At least it did help with some problematic for Qt Windows graphics rendering hardware Integrated Intel® Graphics etc. given ANGLE support though not always a problem for Qt 5. With Qt 6 this may also due to ANGLE being removed from supporting graphics: How to ANGLE在 Qt 6 OpenGL
在这种情况下,还将 QML 与 ListView/etc 一起使用通常会带来更好的图形体验。 Widgets 渲染依赖于 Qt 自己的图形上下文。
另一个考虑因素是适当调整图标大小或更好地使用 1:1 源到视口尺寸。
是的,我修好了。 如果在 Windows 10 操作系统设置(在我的情况下为 125%)中启用了接口缩放,则会检测到问题。 目前还不是很清楚。 问题修复如下:
SqlTableModel::SqlTableModel(QObject *parent, QSqlDatabase db)
: QSqlTableModel(parent, db)
{
auto pixelratio = qApp->primaryScreen()->devicePixelRatio();
auto iconheight = config->GUISize();
m_IconSize = QSize(iconheight, iconheight);
/*...*/
m_ActoinMMIcon = QPixmap(":/resources/img/many_many.svg", "SVG").
scaled(m_IconSize * pixelratio, Qt::KeepAspectRatio, Qt::SmoothTransformation);
m_ActoinMMIcon.setDevicePixelRatio(pixelratio);
/*...*/
}
/* etc */
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.