Changeset View
Changeset View
Standalone View
Standalone View
AuthDialog.cpp
Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 99 | if (message.isEmpty()) { | |||
---|---|---|---|---|---|
100 | qWarning() << "Could not get action message for action."; | 100 | qWarning() << "Could not get action message for action."; | ||
101 | lblHeader->hide(); | 101 | lblHeader->hide(); | ||
102 | } else { | 102 | } else { | ||
103 | qDebug() << "Message of action: " << message; | 103 | qDebug() << "Message of action: " << message; | ||
104 | lblHeader->setText("<h3>" + message + "</h3>"); | 104 | lblHeader->setText("<h3>" + message + "</h3>"); | ||
105 | m_message = message; | 105 | m_message = message; | ||
106 | } | 106 | } | ||
107 | 107 | | |||
108 | const qreal dpr = devicePixelRatioF(); | ||||
apol: You should get the dpr from the window, not the qApp. Different screens will have different… | |||||
guoyunhe: Fixed. Getting it from widget now. | |||||
anthonyfieroni: You wanna use `devicePixelRatioF` right? | |||||
guoyunhe: Fixed thanks! | |||||
109 | | ||||
108 | // loads the standard key icon | 110 | // loads the standard key icon | ||
109 | QPixmap icon = KIconLoader::global()->loadIcon("dialog-password", | 111 | QPixmap icon = KIconLoader::global()->loadIcon("dialog-password", | ||
110 | KIconLoader::NoGroup, | 112 | KIconLoader::NoGroup, | ||
111 | KIconLoader::SizeHuge, | 113 | KIconLoader::SizeHuge * dpr, | ||
112 | KIconLoader::DefaultState); | 114 | KIconLoader::DefaultState); | ||
115 | icon.setDevicePixelRatio(dpr); | ||||
113 | // create a painter to paint the action icon over the key icon | 116 | // create a painter to paint the action icon over the key icon | ||
114 | QPainter painter(&icon); | 117 | QPainter painter(&icon); | ||
115 | const int iconSize = icon.size().width(); | 118 | const int iconSize = icon.size().width(); | ||
116 | // the emblem icon to size 32 | 119 | // the emblem icon to size 32 | ||
117 | int overlaySize = 32; | 120 | int overlaySize = 32; | ||
118 | // try to load the action icon | 121 | // try to load the action icon | ||
119 | const QPixmap pixmap = KIconLoader::global()->loadIcon(iconName, | 122 | QPixmap pixmap = KIconLoader::global()->loadIcon(iconName, | ||
120 | KIconLoader::NoGroup, | 123 | KIconLoader::NoGroup, | ||
121 | overlaySize, | 124 | overlaySize * dpr, | ||
122 | KIconLoader::DefaultState, | 125 | KIconLoader::DefaultState, | ||
123 | QStringList(), | 126 | QStringList(), | ||
124 | nullptr, | 127 | nullptr, | ||
125 | true); | 128 | true); | ||
129 | pixmap.setDevicePixelRatio(dpr); | ||||
126 | // if we're able to load the action icon paint it over the | 130 | // if we're able to load the action icon paint it over the | ||
127 | // key icon. | 131 | // key icon. | ||
128 | if (!pixmap.isNull()) { | 132 | if (!pixmap.isNull()) { | ||
129 | QPoint startPoint; | 133 | QPointF startPoint; | ||
apol: All are integers, why are you turning it into QPointF? | |||||
This is how HiDPI QPainter works. Source https://doc.qt.io/qt-5/highdpi.html#migrate-existing-applications
guoyunhe: This is how HiDPI QPainter works.
Source https://doc.qt.io/qt-5/highdpi.html#migrate-existing… | |||||
130 | // bottom right corner | 134 | // bottom right corner | ||
131 | startPoint = QPoint(iconSize - overlaySize - 2, | 135 | startPoint = QPointF(iconSize - overlaySize - 2, | ||
132 | iconSize - overlaySize - 2); | 136 | iconSize - overlaySize - 2); | ||
133 | painter.drawPixmap(startPoint, pixmap); | 137 | painter.drawPixmap(startPoint, pixmap); | ||
134 | } | 138 | } | ||
135 | 139 | | |||
136 | setWindowIcon(icon); | 140 | setWindowIcon(icon); | ||
137 | lblPixmap->setPixmap(icon); | 141 | lblPixmap->setPixmap(icon); | ||
138 | 142 | | |||
139 | // find action description for actionId | 143 | // find action description for actionId | ||
▲ Show 20 Lines • Show All 246 Lines • Show Last 20 Lines |
You should get the dpr from the window, not the qApp. Different screens will have different dprs.