QDockWidgetTitleButton: Limit icon size to dpiScaled(10) on Windows
Adding larger pixmaps to the icon caused the icon to grow. Task-number: QTBUG-38776 Change-Id: I29148d70afa55e287f2ad254e449a98c4aa631fb Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
This commit is contained in:
parent
d58162127a
commit
43b9c9b993
@ -53,6 +53,7 @@
|
||||
#include <qdebug.h>
|
||||
|
||||
#include <private/qwidgetresizehandler_p.h>
|
||||
#include <private/qstylesheetstyle_p.h>
|
||||
|
||||
#include "qdockwidget_p.h"
|
||||
#include "qmainwindowlayout_p.h"
|
||||
@ -127,8 +128,15 @@ public:
|
||||
void enterEvent(QEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
};
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event) override;
|
||||
|
||||
private:
|
||||
QSize dockButtonIconSize() const;
|
||||
|
||||
mutable int m_iconSize = -1;
|
||||
};
|
||||
|
||||
QDockWidgetTitleButton::QDockWidgetTitleButton(QDockWidget *dockWidget)
|
||||
: QAbstractButton(dockWidget)
|
||||
@ -136,14 +144,49 @@ QDockWidgetTitleButton::QDockWidgetTitleButton(QDockWidget *dockWidget)
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
}
|
||||
|
||||
bool QDockWidgetTitleButton::event(QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::StyleChange:
|
||||
case QEvent::ScreenChangeInternal:
|
||||
m_iconSize = -1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QAbstractButton::event(event);
|
||||
}
|
||||
|
||||
static inline bool isWindowsStyle(const QStyle *style)
|
||||
{
|
||||
// Note: QStyleSheetStyle inherits QWindowsStyle
|
||||
const QStyle *effectiveStyle = style->inherits("QStyleSheetStyle")
|
||||
? static_cast<const QStyleSheetStyle *>(style)->baseStyle()
|
||||
: style;
|
||||
return effectiveStyle->inherits("QWindowsStyle");
|
||||
}
|
||||
|
||||
QSize QDockWidgetTitleButton::dockButtonIconSize() const
|
||||
{
|
||||
if (m_iconSize < 0) {
|
||||
m_iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this);
|
||||
// Dock Widget title buttons on Windows where historically limited to size 10
|
||||
// (from small icon size 16) since only a 10x10 XPM was provided.
|
||||
// Adding larger pixmaps to the icons thus caused the icons to grow; limit
|
||||
// this to qpiScaled(10) here.
|
||||
if (isWindowsStyle(style()))
|
||||
m_iconSize = qMin((10 * logicalDpiX()) / 96, m_iconSize);
|
||||
}
|
||||
return QSize(m_iconSize, m_iconSize);
|
||||
}
|
||||
|
||||
QSize QDockWidgetTitleButton::sizeHint() const
|
||||
{
|
||||
ensurePolished();
|
||||
|
||||
int size = 2*style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin, 0, this);
|
||||
if (!icon().isNull()) {
|
||||
int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
|
||||
QSize sz = icon().actualSize(QSize(iconSize, iconSize));
|
||||
const QSize sz = icon().actualSize(dockButtonIconSize());
|
||||
size += qMax(sz.width(), sz.height());
|
||||
}
|
||||
|
||||
@ -186,8 +229,7 @@ void QDockWidgetTitleButton::paintEvent(QPaintEvent *)
|
||||
opt.activeSubControls = 0;
|
||||
opt.features = QStyleOptionToolButton::None;
|
||||
opt.arrowType = Qt::NoArrow;
|
||||
int size = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
|
||||
opt.iconSize = QSize(size, size);
|
||||
opt.iconSize = dockButtonIconSize();
|
||||
style()->drawComplexControl(QStyle::CC_ToolButton, &opt, &p, this);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user