Changeset View
Changeset View
Standalone View
Standalone View
src/mainwindow.cpp
Show First 20 Lines • Show All 209 Lines • ▼ Show 20 Line(s) | 208 | { | |||
---|---|---|---|---|---|
210 | m_lateral.m_stack = new QStackedWidget(); | 210 | m_lateral.m_stack = new QStackedWidget(); | ||
211 | auto buttonLayout = new QVBoxLayout(); | 211 | auto buttonLayout = new QVBoxLayout(); | ||
212 | 212 | | |||
213 | auto setupButton = [this, buttonLayout](const QString & key, const QString & text, const QIcon & icon, QWidget * w) { | 213 | auto setupButton = [this, buttonLayout](const QString & key, const QString & text, const QIcon & icon, QWidget * w) { | ||
214 | auto *btn = new QPushButton(m_lateral.m_toolBar); | 214 | auto *btn = new QPushButton(m_lateral.m_toolBar); | ||
215 | btn->setToolTip(text); | 215 | btn->setToolTip(text); | ||
216 | btn->setAutoExclusive(true); | 216 | btn->setAutoExclusive(true); | ||
217 | btn->setCheckable(true); | 217 | btn->setCheckable(true); | ||
218 | //3d view is on top set it checked so users see its selected. | 218 | //Check the top most widget, so users see its selected at startup time. | ||
219 | btn->setChecked(key == QStringLiteral("welcome")); | 219 | btn->setChecked(key == QStringLiteral("welcome")); | ||
220 | btn->setIcon(icon); | 220 | btn->setIcon(icon); | ||
221 | //Set an iconSize based on the DPI. | 221 | //Set an iconSize based on the DPI. | ||
222 | //96 was considered to be the "standard" DPI for years. | 222 | //96 was considered to be the "standard" DPI for years. | ||
223 | //Hi-dpi monitors have a higher DPI | 223 | //Hi-dpi monitors have a higher DPI; 150+ | ||
224 | //Tiny or old screen could have a lower DPI. | 224 | //Tiny or old screen could have a lower DPI. | ||
225 | //Start our iconSize at 16 so with a DPI less then 96 we get a sane iconsize. | 225 | //Start our iconSize at 16 so with a low DPI we get a sane iconsize. | ||
226 | int iconSize = 16 + ((logicalDpiX() / 96) * 16); | 226 | //Use 72 to better scale for less dense Hi-Dpi screens | ||
227 | int iconSize = 16 + ((logicalDpiX() / 72) * 16); | ||||
laysrodrigues: don't use magic numbers... | |||||
This is exactly how it was done before but using 96. While 96 is the "standard", using 72 works for the range of hi-dpi density better as the DPI varies slightly depending on physical size and native resolution. This fixes an issue where on the icon is correctly scaled on a 15" Hi-dpi display (DPI is 196) and its not scaled on another 28" Hi-Dpi display with a DPI of 162 . Both screens are 4k and both should be scaled. I adjusted the comment so the number is not magic its explained above the line. I didn't think it was worth making a variable to store a one time use number because as a said it was already done this way before my change. rizzitello: This is exactly how it was done before but using 96. While 96 is the "standard", using 72… | |||||
227 | btn->setIconSize(QSize(iconSize, iconSize)); | 228 | btn->setIconSize(QSize(iconSize, iconSize)); | ||
228 | btn->setFixedSize(btn->iconSize()); | 229 | btn->setFixedSize(btn->iconSize()); | ||
229 | btn->setFlat(true); | 230 | btn->setFlat(true); | ||
230 | m_lateral.m_stack->addWidget(w); | 231 | m_lateral.m_stack->addWidget(w); | ||
231 | m_lateral.m_map[key] = {btn, w}; | 232 | m_lateral.m_map[key] = {btn, w}; | ||
232 | buttonLayout->addWidget(btn); | 233 | buttonLayout->addWidget(btn); | ||
233 | 234 | | |||
234 | connect(btn, &QPushButton::clicked, this, [this, w, btn] { | 235 | connect(btn, &QPushButton::clicked, this, [this, w, btn] { | ||
▲ Show 20 Lines • Show All 259 Lines • Show Last 20 Lines |
don't use magic numbers...