From 059831534c7e884f0a607ed86b582fd00d821731 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Sat, 26 Sep 2026 23:24:03 +0200 Subject: New upstream version 3.2.0~rc1+dfsg --- widgets/CompactButtonSize.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 widgets/CompactButtonSize.hpp (limited to 'widgets/CompactButtonSize.hpp') diff --git a/widgets/CompactButtonSize.hpp b/widgets/CompactButtonSize.hpp new file mode 100644 index 00000000..d9455456 --- /dev/null +++ b/widgets/CompactButtonSize.hpp @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +#ifndef COMPACT_BUTTON_SIZE_HPP +#define COMPACT_BUTTON_SIZE_HPP + +#include +#include +#include + +// Measure the label and native decoration without the style's recommended +// dialog-button width (75 logical pixels on Windows). Painting stays native. +inline QSize compactButtonSize (QPushButton const * button) +{ + QStyleOptionButton option; + option.initFrom (button); + if (button->autoDefault ()) option.features |= QStyleOptionButton::AutoDefaultButton; + auto contents = button->fontMetrics ().size (Qt::TextShowMnemonic, button->text ()); + // The text is already measured above. An empty option text avoids the + // Windows style's dialog-width floor without discarding its frame margins. + return button->style ()->sizeFromContents (QStyle::CT_PushButton, &option, contents, button); +} + +#endif -- cgit v1.2.3