PerScreenDpi | QLabels incorrectly handle scale for icons (#4070)
* Fixes to icon generation. Generating a pixmap out of a size won't take the screen scaling factor into account, resulting in blurry results. Note that this is not a catchall solution, every case needs to be addressed manually. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * HighDpi fixes for startup splashscreen and About dialog Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Add helper function to generate appropriate pixmaps for a screen based on its dpi settings. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Casting/numeric_cast.h>
|
||||
#include <AzQtComponents/Utilities/PixmapScaleUtilities.h>
|
||||
|
||||
#include <QtGui/private/qhighdpiscaling_p.h>
|
||||
|
||||
namespace AzQtComponents
|
||||
{
|
||||
QPixmap ScalePixmapForScreenDpi(
|
||||
QPixmap pixmap, QScreen* screen, QSize size, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode)
|
||||
{
|
||||
qreal screenDpiFactor = QHighDpiScaling::factor(screen);
|
||||
pixmap.setDevicePixelRatio(screenDpiFactor);
|
||||
|
||||
QPixmap scaledPixmap;
|
||||
|
||||
size.setWidth(aznumeric_cast<int>(aznumeric_cast<qreal>(size.width()) * screenDpiFactor));
|
||||
size.setHeight(aznumeric_cast<int>(aznumeric_cast<qreal>(size.height()) * screenDpiFactor));
|
||||
|
||||
scaledPixmap = pixmap.scaled(size, aspectRatioMode, transformationMode);
|
||||
|
||||
return scaledPixmap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzQtComponents/AzQtComponentsAPI.h>
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QScreen>
|
||||
|
||||
namespace AzQtComponents
|
||||
{
|
||||
AZ_QT_COMPONENTS_API QPixmap ScalePixmapForScreenDpi(QPixmap pixmap, QScreen* screen, QSize size, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode);
|
||||
}; // namespace AzQtComponents
|
||||
@@ -276,6 +276,8 @@ set(FILES
|
||||
Utilities/HandleDpiAwareness.cpp
|
||||
Utilities/HandleDpiAwareness.h
|
||||
Utilities/MouseHider.h
|
||||
Utilities/PixmapScaleUtilities.cpp
|
||||
Utilities/PixmapScaleUtilities.h
|
||||
Utilities/QtPluginPaths.cpp
|
||||
Utilities/QtPluginPaths.h
|
||||
Utilities/QtWindowUtilities.cpp
|
||||
|
||||
Reference in New Issue
Block a user