简体   繁体   English

Windows 中的低质量 QPixmap

[英]Low quality QPixmap in Windows

I am uploading QPixmap to QTableView via QSqlTableModel.我正在通过 QSqlTableModel 将 QPixmap 上传到 QTableView。 On Linux, images are displayed in normal quality, but on Windows, the image quality is very low.在 Linux 上,图像以正常质量显示,但在 Windows 上,图像质量非常低。 Is it possible to fix it somehow?有没有可能以某种方式修复它?

Qt 6 Qt 6

fragment of my code:我的代码片段:

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);
}

Linux: Linux: Linux

Windows: Windows: 视窗

Before Qt 6 in the main() function before the app.exec() call we used to setting these: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 in Qt 6 OpenGL 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

Also using QML with ListView/etc for such case usually makes much better graphics experience.在这种情况下,还将 QML 与 ListView/etc 一起使用通常会带来更好的图形体验。 Widgets rendering depends on Qt's own graphics context. Widgets 渲染依赖于 Qt 自己的图形上下文。

One more consideration is proper sizing of icons or better use 1:1 source to viewport dimensions.另一个考虑因素是适当调整图标大小或更好地使用 1:1 源到视口尺寸。

Yes, I fixed it.是的,我修好了。 The problem is detected if the interface scaling is enabled in the Windows 10 OS settings (in my case it is 125%).如果在 Windows 10 操作系统设置(在我的情况下为 125%)中启用了接口缩放,则会检测到问题。 It wasn't immediately clear.目前还不是很清楚。 The problem is fixed as follows:问题修复如下:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM