summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-02-20 11:37:41 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-02-22 10:05:03 +0100
commit835e18d9ff79867f508fc8baac7fcc5bb4efc0cb (patch)
tree8e6268c9bf7747f138514dceb5382fafab67ff3e /src/widgets/widgets
parentc58ee54a707717b142f6e90cf48302884feb0b12 (diff)
Fix wrong DPI used by QStyle::pixelMetric()
Pass on the option or the widget in order to ensure usage of the correct DPI for High DPI scaling. Task-number: QTBUG-82356 Change-Id: I5df903a83f88adebd143e514e2fead367d39f015 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r--src/widgets/widgets/qcalendarwidget.cpp4
-rw-r--r--src/widgets/widgets/qcombobox_p.h2
-rw-r--r--src/widgets/widgets/qcommandlinkbutton.cpp8
-rw-r--r--src/widgets/widgets/qfocusframe.cpp12
-rw-r--r--src/widgets/widgets/qgroupbox.cpp6
-rw-r--r--src/widgets/widgets/qlineedit.cpp2
-rw-r--r--src/widgets/widgets/qmenu.cpp2
-rw-r--r--src/widgets/widgets/qmenubar.cpp2
-rw-r--r--src/widgets/widgets/qtoolbarextension.cpp4
-rw-r--r--src/widgets/widgets/qwidgettextcontrol.cpp2
10 files changed, 25 insertions, 19 deletions
diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp
index 8593001f8b..da958a61dc 100644
--- a/src/widgets/widgets/qcalendarwidget.cpp
+++ b/src/widgets/widgets/qcalendarwidget.cpp
@@ -2232,7 +2232,9 @@ QSize QCalendarWidget::minimumSizeHint() const
int rows = 7;
int cols = 8;
- const int marginH = (style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1) * 2;
+ QStyleOption option;
+ option.initFrom(this);
+ const int marginH = (style()->pixelMetric(QStyle::PM_FocusFrameHMargin, &option) + 1) * 2;
if (horizontalHeaderFormat() == QCalendarWidget::NoHorizontalHeader) {
rows = 6;
diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h
index 5967776a61..8d660c11e1 100644
--- a/src/widgets/widgets/qcombobox_p.h
+++ b/src/widgets/widgets/qcombobox_p.h
@@ -146,7 +146,7 @@ public:
setAttribute(Qt::WA_NoMousePropagation);
}
QSize sizeHint() const override {
- return QSize(20, style()->pixelMetric(QStyle::PM_MenuScrollerHeight));
+ return QSize(20, style()->pixelMetric(QStyle::PM_MenuScrollerHeight, nullptr, this));
}
protected:
diff --git a/src/widgets/widgets/qcommandlinkbutton.cpp b/src/widgets/widgets/qcommandlinkbutton.cpp
index 2b9258fd91..e9462ed229 100644
--- a/src/widgets/widgets/qcommandlinkbutton.cpp
+++ b/src/widgets/widgets/qcommandlinkbutton.cpp
@@ -208,7 +208,7 @@ bool QCommandLinkButtonPrivate::usingVistaStyle() const
//### This is a hack to detect if we are indeed running Vista style themed and not in classic
// When we add api to query for this, we should change this implementation to use it.
return q->style()->inherits("QWindowsVistaStyle")
- && !q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal);
+ && q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal, nullptr) == 0;
}
void QCommandLinkButtonPrivate::init()
@@ -355,8 +355,10 @@ void QCommandLinkButton::paintEvent(QPaintEvent *)
option.icon = QIcon(); //we draw this ourselves
QSize pixmapSize = icon().actualSize(iconSize());
- int vOffset = isDown() ? style()->pixelMetric(QStyle::PM_ButtonShiftVertical) : 0;
- int hOffset = isDown() ? style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal) : 0;
+ const int vOffset = isDown()
+ ? style()->pixelMetric(QStyle::PM_ButtonShiftVertical, &option) : 0;
+ const int hOffset = isDown()
+ ? style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal, &option) : 0;
//Draw icon
p.drawControl(QStyle::CE_PushButton, option);
diff --git a/src/widgets/widgets/qfocusframe.cpp b/src/widgets/widgets/qfocusframe.cpp
index 0992becdf0..c5b2a32aec 100644
--- a/src/widgets/widgets/qfocusframe.cpp
+++ b/src/widgets/widgets/qfocusframe.cpp
@@ -86,8 +86,10 @@ void QFocusFramePrivate::updateSize()
if (!widget)
return;
- int vmargin = q->style()->pixelMetric(QStyle::PM_FocusFrameVMargin),
- hmargin = q->style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
+ QStyleOption opt;
+ q->initStyleOption(&opt);
+ int vmargin = q->style()->pixelMetric(QStyle::PM_FocusFrameVMargin, &opt),
+ hmargin = q->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, &opt);
QPoint pos(widget->x(), widget->y());
if (q->parentWidget() != widget->parentWidget())
pos = widget->parentWidget()->mapTo(q->parentWidget(), pos);
@@ -98,8 +100,6 @@ void QFocusFramePrivate::updateSize()
q->setGeometry(geom);
QStyleHintReturnMask mask;
- QStyleOption opt;
- q->initStyleOption(&opt);
if (q->style()->styleHint(QStyle::SH_FocusFrame_Mask, &opt, q, &mask))
q->setMask(mask.region);
}
@@ -263,8 +263,8 @@ QFocusFrame::paintEvent(QPaintEvent *)
QStylePainter p(this);
QStyleOption option;
initStyleOption(&option);
- int vmargin = style()->pixelMetric(QStyle::PM_FocusFrameVMargin);
- int hmargin = style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
+ const int vmargin = style()->pixelMetric(QStyle::PM_FocusFrameVMargin, &option);
+ const int hmargin = style()->pixelMetric(QStyle::PM_FocusFrameHMargin, &option);
QWidgetPrivate *wd = qt_widget_private(d->widget);
QRect rect = wd->clipRect().adjusted(0, 0, hmargin*2, vmargin*2);
p.setClipRect(rect);
diff --git a/src/widgets/widgets/qgroupbox.cpp b/src/widgets/widgets/qgroupbox.cpp
index eec794562a..735e950602 100644
--- a/src/widgets/widgets/qgroupbox.cpp
+++ b/src/widgets/widgets/qgroupbox.cpp
@@ -491,9 +491,9 @@ QSize QGroupBox::minimumSizeHint() const
int baseWidth = metrics.horizontalAdvance(d->title) + metrics.horizontalAdvance(QLatin1Char(' '));
int baseHeight = metrics.height();
if (d->checkable) {
- baseWidth += style()->pixelMetric(QStyle::PM_IndicatorWidth);
- baseWidth += style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing);
- baseHeight = qMax(baseHeight, style()->pixelMetric(QStyle::PM_IndicatorHeight));
+ baseWidth += style()->pixelMetric(QStyle::PM_IndicatorWidth, &option);
+ baseWidth += style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, &option);
+ baseHeight = qMax(baseHeight, style()->pixelMetric(QStyle::PM_IndicatorHeight, &option));
}
QSize size = style()->sizeFromContents(QStyle::CT_GroupBox, &option, QSize(baseWidth, baseHeight), this);
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index 658315028a..eaf31551d9 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -2073,7 +2073,7 @@ void QLineEdit::paintEvent(QPaintEvent *)
if (d->cursorVisible && !d->control->isReadOnly())
flags |= QWidgetLineControl::DrawCursor;
- d->control->setCursorWidth(style()->pixelMetric(QStyle::PM_TextCursorWidth));
+ d->control->setCursorWidth(style()->pixelMetric(QStyle::PM_TextCursorWidth, &panel));
d->control->draw(&p, topLeft, r, flags);
}
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 57ef7905d9..2d6e6179af 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -2828,7 +2828,7 @@ void QMenu::paintEvent(QPaintEvent *e)
frame.rect = rect();
frame.palette = palette();
frame.state = QStyle::State_None;
- frame.lineWidth = style()->pixelMetric(QStyle::PM_MenuPanelWidth);
+ frame.lineWidth = style()->pixelMetric(QStyle::PM_MenuPanelWidth, &frame);
frame.midLineWidth = 0;
style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, &p, this);
}
diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp
index 7a751597bc..a2087c8ab1 100644
--- a/src/widgets/widgets/qmenubar.cpp
+++ b/src/widgets/widgets/qmenubar.cpp
@@ -1019,7 +1019,7 @@ void QMenuBar::paintEvent(QPaintEvent *e)
frame.rect = rect();
frame.palette = palette();
frame.state = QStyle::State_None;
- frame.lineWidth = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth);
+ frame.lineWidth = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, &frame);
frame.midLineWidth = 0;
style()->drawPrimitive(QStyle::PE_PanelMenuBar, &frame, &p, this);
}
diff --git a/src/widgets/widgets/qtoolbarextension.cpp b/src/widgets/widgets/qtoolbarextension.cpp
index bbe7eddaa4..165c7f274b 100644
--- a/src/widgets/widgets/qtoolbarextension.cpp
+++ b/src/widgets/widgets/qtoolbarextension.cpp
@@ -81,7 +81,9 @@ void QToolBarExtension::paintEvent(QPaintEvent *)
QSize QToolBarExtension::sizeHint() const
{
- int ext = style()->pixelMetric(QStyle::PM_ToolBarExtensionExtent);
+ QStyleOption opt;
+ opt.initFrom(this);
+ const int ext = style()->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt);
return QSize(ext, ext);
}
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp
index 83e2315c36..fb41f38b5a 100644
--- a/src/widgets/widgets/qwidgettextcontrol.cpp
+++ b/src/widgets/widgets/qwidgettextcontrol.cpp
@@ -2463,7 +2463,7 @@ void QWidgetTextControl::setCursorWidth(int width)
Q_UNUSED(width);
#else
if (width == -1)
- width = QApplication::style()->pixelMetric(QStyle::PM_TextCursorWidth);
+ width = QApplication::style()->pixelMetric(QStyle::PM_TextCursorWidth, nullptr);
d->doc->documentLayout()->setProperty("cursorWidth", width);
#endif
d->repaintCursor();