New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Qt: Fix HiDPI icon scaling #5463
Conversation
| @@ -93,7 +93,10 @@ void ControllersWindow::CreateGamecubeLayout() | |||
| m_gc_box = new QGroupBox(); | |||
| m_gc_layout = new QFormLayout(); | |||
| m_gc_label = new QLabel(); | |||
| m_gc_label->setPixmap(QPixmap(m_gamecube_icon)); | |||
|
|
|||
| auto pixmap = QPixmap(m_gamecube_icon).scaled(QSize(64, 64)); | |||
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
e2c4490
to
21c9891
Compare
1919a22
to
7ea4b1c
Compare
|
Ready to be reviewed & merged now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I've missed something, the game list is still using low-res images on high-DPI screens.
| m_wii_icon(Settings().GetResourcesDir().append(QStringLiteral("Platform_Wii.png"))) | ||
| m_gamecube_icon( | ||
| Settings().GetResourcesDir().append(QStringLiteral("Platform_Gamecube@2x.png"))), | ||
| m_wii_icon(Settings().GetResourcesDir().append(QStringLiteral("Platform_Wii@2x.png"))) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| std::string number = QString::number(num, 'f', 1).toStdString(); | ||
|
|
||
| if (num == static_cast<int>(num)) | ||
| number = number.substr(0, number.length() - 2); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
7a445e7
to
8b3216f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still doesn't work on macOS, use the Qt HighDpi attributes, or use devicePixelRatio() correctly. Could you please go over the patch I posted above again, and make sure you understand it? I'm usually on IRC if you have more questions.
Source/Core/DolphinQt2/DPI.cpp
Outdated
| { | ||
| double GetScale() | ||
| { | ||
| return static_cast<QGuiApplication*>(QGuiApplication::instance())->devicePixelRatio() * 1.1; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/DPI.cpp
Outdated
| return static_cast<QGuiApplication*>(QGuiApplication::instance())->devicePixelRatio() * 1.1; | ||
| } | ||
|
|
||
| double GetScaledIconSize(const double scale) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| std::string number = QString::number(num, 'f', 1).toStdString(); | ||
|
|
||
| if (num == static_cast<int>(num)) | ||
| number = number.substr(0, number.length() - 2); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| @@ -83,7 +83,7 @@ void GameList::MakeTableView() | |||
| QHeaderView* hor_header = m_table->horizontalHeader(); | |||
| hor_header->setSectionResizeMode(GameListModel::COL_PLATFORM, QHeaderView::ResizeToContents); | |||
| hor_header->setSectionResizeMode(GameListModel::COL_COUNTRY, QHeaderView::ResizeToContents); | |||
| hor_header->setSectionResizeMode(GameListModel::COL_ID, QHeaderView::ResizeToContents); | |||
| hor_header->setSectionResizeMode(GameListModel::COL_ID, QHeaderView::Fixed); | |||
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| case GameListModel::COL_ID: | ||
| painter->drawText(option.rect, |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| const auto height = | ||
| static_cast<double>(pixmap.height()) / (icon_scaled ? Resources::GetIconScale() : 1) * scale; | ||
|
|
||
| DrawPixmap(painter, rect, icon_scaled ? |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| @@ -11,10 +11,13 @@ class TableDelegate final : public QStyledItemDelegate | |||
| Q_OBJECT | |||
|
|
|||
| public: | |||
| explicit TableDelegate(QWidget* parent = nullptr); | |||
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| void DrawPixmap(QPainter* painter, const QRect& rect, const QPixmap& pixmap) const; | ||
| void DrawPixmap(QPainter* painter, const QRect& rect, const QPixmap& pixmap, | ||
| const QSize& size) const; | ||
| void DrawPixmap(QPainter* painter, const QRect& rect, const QPixmap& pixmap, |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/ToolBar.cpp
Outdated
| { | ||
| setToolButtonStyle(Qt::ToolButtonTextUnderIcon); | ||
| setMovable(false); | ||
| setFloatable(false); | ||
| setIconSize(ICON_SIZE); | ||
| setIconSize(ICON_SIZE * m_scale); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/ToolBar.cpp
Outdated
| m_controllers_action->setIcon(QIcon(QStringLiteral("classic.png").prepend(dir))); | ||
| const QString suffix = DPI::GetScaledIconSuffix(m_scale, 2); | ||
|
|
||
| m_open_action->setIcon(QIcon(QStringLiteral("open%1.png").arg(suffix).prepend(dir))); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| break; | ||
| case GameListModel::COL_BANNER: | ||
| DrawPixmap(painter, option.rect, | ||
| data.value<QPixmap>().scaled(NORMAL_BANNER_SIZE, Qt::KeepAspectRatio, | ||
| Qt::SmoothTransformation)); | ||
| data.value<QPixmap>().scaled(NORMAL_BANNER_SIZE * scale, Qt::KeepAspectRatio, |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
65e643c
to
3846e90
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than a few comments, tested and LGTM.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| for (QString country : countries) | ||
| m_countries.append(QPixmap(country.prepend(sys_dir))); | ||
| m_countries.append(QPixmap(country.arg(GetPreferredIconScale()).prepend(sys_dir))); | ||
|
|
||
| QStringList ratings{QStringLiteral("rating0.png"), QStringLiteral("rating1.png"), |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| @@ -40,7 +56,9 @@ void Resources::Init() | |||
| m_ratings.append(QPixmap(rating.prepend(sys_dir))); | |||
|
|
|||
| m_misc.append(QPixmap(QStringLiteral("nobanner.png").prepend(sys_dir))); | |||
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| m_misc.append(QPixmap(QStringLiteral("dolphin_logo.png").prepend(sys_dir))); | ||
| m_misc.append(QPixmap(QStringLiteral("dolphin_logo%1.png") | ||
| .arg(Resources::GetPreferredIconScale()) | ||
| .prepend(sys_dir))); | ||
| m_misc.append(QPixmap(QStringLiteral("Dolphin.png").prepend(sys_dir))); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great on macOS. Couple code cleanup things.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| for (QString country : countries) | ||
| m_countries.append(QPixmap(country.prepend(sys_dir))); | ||
| m_countries.append(QPixmap(country.arg(GetPreferredIconScale()).prepend(sys_dir))); | ||
|
|
||
| QStringList ratings{QStringLiteral("rating0.png"), QStringLiteral("rating1.png"), |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| m_misc.append(QPixmap(QStringLiteral("dolphin_logo.png").prepend(sys_dir))); | ||
| m_misc.append(QPixmap(QStringLiteral("dolphin_logo%1.png") | ||
| .arg(Resources::GetPreferredIconScale()) | ||
| .prepend(sys_dir))); | ||
| m_misc.append(QPixmap(QStringLiteral("Dolphin.png").prepend(sys_dir))); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/ToolBar.cpp
Outdated
| m_screenshot_action->setIcon(QIcon(QStringLiteral("screenshot.png").prepend(dir))); | ||
| m_config_action->setIcon(QIcon(QStringLiteral("config.png").prepend(dir))); | ||
| m_controllers_action->setIcon(QIcon(QStringLiteral("classic.png").prepend(dir))); | ||
| m_open_action->setIcon( |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| @@ -13,25 +17,37 @@ QList<QPixmap> Resources::m_countries; | |||
| QList<QPixmap> Resources::m_ratings; | |||
| QList<QPixmap> Resources::m_misc; | |||
|
|
|||
| QString Resources::GetPreferredIconScale(int max) | |||
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| for (QString country : countries) | ||
| m_countries.append(QPixmap(country.prepend(sys_dir))); | ||
| m_countries.append(QPixmap(country.arg(GetPreferredIconScale()).prepend(sys_dir))); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
dffdf50
to
df36821
Compare
Source/Core/DolphinQt2/Resources.cpp
Outdated
| for (QString platform : platforms) | ||
| m_platforms.append(QPixmap(platform.prepend(sys_dir))); | ||
| m_platforms.append(GetScaledIcon(platform.prepend(QStringLiteral("Platform_")))); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| for (QString country : countries) | ||
| m_countries.append(QPixmap(country.prepend(sys_dir))); | ||
| m_countries.append(GetScaledIcon(country.prepend(QStringLiteral("Flag_")))); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/ToolBar.cpp
Outdated
| m_fullscreen_action->setIcon(QIcon(Resources::GetScaledThemeIcon(QStringLiteral("fullscreen")))); | ||
| m_screenshot_action->setIcon(QIcon(Resources::GetScaledThemeIcon(QStringLiteral("screenshot")))); | ||
| m_config_action->setIcon(QIcon(Resources::GetScaledThemeIcon(QStringLiteral("config")))); | ||
| m_controllers_action->setIcon(QIcon(Resources::GetScaledThemeIcon(QStringLiteral("classic")))); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| @@ -13,25 +17,37 @@ QList<QPixmap> Resources::m_countries; | |||
| QList<QPixmap> Resources::m_ratings; | |||
| QList<QPixmap> Resources::m_misc; | |||
|
|
|||
| QString Resources::GetPreferredIconScale(int max) | |||
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| return QStringLiteral(""); | ||
| } | ||
|
|
||
| QPixmap Resources::GetScaledIcon(const QString& name, int max, const QString& dir) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| return QStringLiteral(""); | ||
| } | ||
|
|
||
| QPixmap Resources::GetScaledIcon(const QString& name, int max, const QString& dir) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
|
|
||
| QList<QPixmap> Resources::m_platforms; | ||
| QList<QPixmap> Resources::m_countries; | ||
| QList<QPixmap> Resources::m_ratings; | ||
| QList<QPixmap> Resources::m_misc; | ||
|
|
||
| QString Resources::GetPreferredIconScale(int max) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.h
Outdated
| @@ -26,6 +26,11 @@ class Resources final | |||
| LOGO_SMALL | |||
| }; | |||
|
|
|||
| static QString GetPreferredIconScale(int max = 4); | |||
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.h
Outdated
| static QString GetPreferredIconScale(int max = 4); | ||
| static QPixmap GetScaledIcon(const QString& name, int max = 4, | ||
| const QString& dir = QStringLiteral("")); | ||
| static QPixmap GetScaledThemeIcon(const QString& name, int max = 4); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
I think this can be merged now as all points have been addressed |
|
@spycrab That's not how it works :) Make changes, get more reviews, then merge. |
Source/Core/DolphinQt2/Resources.cpp
Outdated
| return QStringLiteral(""); | ||
| } | ||
|
|
||
| QPixmap Resources::GetScaledPixmap(const std::string& name, int max, Resources::Directory dir) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.h
Outdated
| Theme | ||
| }; | ||
|
|
||
| static QString GetPreferredIconScale(int max = 4); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/ToolBar.cpp
Outdated
| m_screenshot_action->setIcon(QIcon(QStringLiteral("screenshot.png").prepend(dir))); | ||
| m_config_action->setIcon(QIcon(QStringLiteral("config.png").prepend(dir))); | ||
| m_controllers_action->setIcon(QIcon(QStringLiteral("classic.png").prepend(dir))); | ||
| m_open_action->setIcon(QIcon(Resources::GetScaledPixmap("open", 4, Resources::Directory::Theme))); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
|
|
||
| QList<QPixmap> Resources::m_platforms; | ||
| QList<QPixmap> Resources::m_countries; | ||
| QList<QPixmap> Resources::m_ratings; | ||
| QList<QPixmap> Resources::m_misc; | ||
|
|
||
| QString Resources::GetPreferredPixmapScale(int max) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
21721f8
to
37db2f8
Compare
Source/Core/DolphinQt2/Resources.cpp
Outdated
| QPixmap pixmap; | ||
| for (int scale : {4, 2, 1}) | ||
| { | ||
| pixmap = QPixmap(QStringLiteral("%1%2%3.png") |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| return QStringLiteral(""); | ||
| } | ||
|
|
||
| QPixmap Resources::GetScaledPixmap(const std::string& name, bool is_themed) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| QPixmap Resources::GetScaledPixmap(const std::string& name, bool is_themed) | ||
| { | ||
| QPixmap pixmap; | ||
| for (int scale : {4, 2, 1}) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
@ligfx Can you take a look again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @spycrab! One small thing left.
Source/Core/DolphinQt2/Resources.cpp
Outdated
| const auto sizes = icon.availableSizes(); | ||
| const auto dpr = QGuiApplication::primaryScreen()->devicePixelRatio(); | ||
|
|
||
| return icon.pixmap(sizes[std::min((dpr <= 1) ? 1 : (dpr <= 2) ? 2 : 4, sizes.size() - 1)]); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, that fixed it. Great job. This makes DolphinQt2 look so much better!

No description provided.