frontend: Improve High DPI support and scaling

This patch enhances High DPI support across the Qt frontend with the following improvements:

**Windows DPI Awareness:**
- Add shellscalingapi.h include for Windows DPI functions
- Implement Per Monitor DPI Awareness (Windows 8.1+) and Per Monitor v2 DPI Awareness (Windows 10+)
- Use SetProcessDPIAware() and SetProcessDpiAwareness() for better multi-monitor scaling
- Dynamically load shcore.dll to access modern DPI awareness APIs

**Configuration Dialog Enhancements:**
- Add comprehensive High DPI responsive CSS media queries for different DPI levels (192dpi, 240dpi)
- Scale UI elements (buttons, comboboxes, line edits, checkboxes, radio buttons) based on screen DPI
- Improve scroll area styling with proper scrollbar theming for high DPI displays
- Set proper window attributes for scaling (WA_TranslucentBackground, WA_NoSystemBackground)
- Calculate logical window size based on device pixel ratio for accurate scaling

**UI Improvements:**
- Enhanced scroll area styling with custom scrollbar appearance
- Better visual feedback with hover effects on scrollbar handles
- Improved spacing and sizing for high DPI displays
- Set proper window modality and title for configuration dialog

These changes provide better visual quality and usability on high DPI displays, particularly on Windows systems with multiple monitors or high-resolution screens. The scaling is now more accurate and consistent across different display configurations.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
Zephyron
2025-07-22 16:30:47 +10:00
parent bd6dd7f0ff
commit f5bea18fd9
3 changed files with 169 additions and 3 deletions

View File

@@ -43,7 +43,60 @@ QScrollArea* CreateScrollArea(QWidget* widget) {
scroll_area->setFrameShape(QFrame::NoFrame);
scroll_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scroll_area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scroll_area->setStyleSheet(QLatin1String("QScrollArea { border: none; background-color: #2b2b2b; }"));
// High DPI support: Scroll area will inherit scaling from parent
// Set style with high DPI aware styling
scroll_area->setStyleSheet(QLatin1String(
"QScrollArea { "
"border: none; "
"background-color: #2b2b2b; "
"}"
"QScrollArea > QWidget > QWidget { "
"background-color: #2b2b2b; "
"}"
"QScrollBar:vertical { "
"background-color: #3d3d3d; "
"width: 14px; "
"border-radius: 7px; "
"margin: 2px; "
"}"
"QScrollBar::handle:vertical { "
"background-color: #5d5d5d; "
"border-radius: 6px; "
"min-height: 30px; "
"margin: 1px; "
"}"
"QScrollBar::handle:vertical:hover { "
"background-color: #4a9eff; "
"}"
"QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { "
"border: none; "
"background: none; "
"height: 0px; "
"}"
"QScrollBar:horizontal { "
"background-color: #3d3d3d; "
"height: 14px; "
"border-radius: 7px; "
"margin: 2px; "
"}"
"QScrollBar::handle:horizontal { "
"background-color: #5d5d5d; "
"border-radius: 6px; "
"min-width: 30px; "
"margin: 1px; "
"}"
"QScrollBar::handle:horizontal:hover { "
"background-color: #4a9eff; "
"}"
"QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal { "
"border: none; "
"background: none; "
"width: 0px; "
"}"
));
return scroll_area;
}
@@ -81,16 +134,28 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_,
setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::WindowSystemMenuHint |
Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
// High DPI support: Set proper attributes for scaling
setAttribute(Qt::WA_TranslucentBackground, false);
setAttribute(Qt::WA_NoSystemBackground, false);
setAttribute(Qt::WA_DontShowOnScreen, false);
ui->setupUi(this);
// Set size policy and enable resizing
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// Get screen geometry and set to fullscreen
// Get screen geometry and set to fullscreen with high DPI awareness
QScreen* screen = QApplication::primaryScreen();
if (screen) {
QRect screenGeometry = screen->availableGeometry();
setGeometry(screenGeometry);
// Calculate logical size based on device pixel ratio for high DPI support
qreal devicePixelRatio = screen->devicePixelRatio();
int logicalWidth = static_cast<int>(screenGeometry.width() / devicePixelRatio);
int logicalHeight = static_cast<int>(screenGeometry.height() / devicePixelRatio);
// Set geometry using logical units
setGeometry(0, 0, logicalWidth, logicalHeight);
showMaximized(); // Start maximized/fullscreen
}