[英]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.