diff options
| author | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:03 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:03 +0200 |
| commit | 059831534c7e884f0a607ed86b582fd00d821731 (patch) | |
| tree | 76bcb67a78f8aa2654fd34c2ad801a62136b0170 /widgets/CompactButtonSize.hpp | |
| parent | d83a420f0517d7fc47aeb288a6a0cf4891784fcc (diff) | |
New upstream version 3.2.0~rc1+dfsgupstream/3.2.0_rc1+dfsg
Diffstat (limited to 'widgets/CompactButtonSize.hpp')
| -rw-r--r-- | widgets/CompactButtonSize.hpp | 22 |
1 files changed, 22 insertions, 0 deletions
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 <QPushButton> +#include <QStyle> +#include <QStyleOptionButton> + +// 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 |
