Enable High-DPI scaling by default in all my Qt applications

This commit is contained in:
Martchus 2020-07-12 21:15:48 +02:00
parent abfcd9f8be
commit 56cf474231
3 changed files with 21 additions and 3 deletions

View File

@ -9,7 +9,7 @@ set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION
"Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models")
set(META_VERSION_MAJOR 6)
set(META_VERSION_MINOR 1)
set(META_VERSION_MINOR 2)
set(META_VERSION_PATCH 0)
set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH})

View File

@ -298,4 +298,18 @@ bool hasCoreApp()
}
} // namespace ApplicationInstances
/*!
* \brief Sets Qt application attributes which are commonly used within my Qt applications.
* \remarks
* - So far this enables High-DPI support.
* - The exact attributes are unspecified and might change to whatever makes sense in the future.
*/
void setupCommonQtApplicationAttributes()
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
}
// namespace ApplicationInstances
} // namespace QtUtilities

View File

@ -12,14 +12,16 @@ QT_FORWARD_DECLARE_CLASS(QStringList)
QT_FORWARD_DECLARE_CLASS(QSettings)
/*!
* \brief Sets the application meta data in the QCoreApplication singleton.
* \brief Sets the application meta data in the QCoreApplication singleton and attributes commonly used
* within my applications.
* \sa ::QtUtilities::setupCommonQtApplicationAttributes()
*/
#define SET_QT_APPLICATION_INFO \
QCoreApplication::setOrganizationName(QStringLiteral(APP_AUTHOR)); \
QCoreApplication::setOrganizationDomain(QStringLiteral(APP_DOMAIN)); \
QCoreApplication::setApplicationName(QStringLiteral(APP_NAME)); \
QCoreApplication::setApplicationVersion(QStringLiteral(APP_VERSION)); \
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true)
::QtUtilities::setupCommonQtApplicationAttributes()
/*!
* \brief Loads translations for Qt, other dependencies and the application.
@ -59,6 +61,8 @@ QT_UTILITIES_EXPORT bool hasGuiApp();
QT_UTILITIES_EXPORT bool hasCoreApp();
} // namespace ApplicationInstances
QT_UTILITIES_EXPORT void setupCommonQtApplicationAttributes();
} // namespace QtUtilities
#endif // APPLICATION_UTILITIES_RESOURCES_H