Commit f486a2f5 authored by Noah Davis's avatar Noah Davis 🌵
Browse files

StatusBarToolButton: give icon-only buttons same height as text-only and square dimentions

Also make text-only the same height as icon-only when text height is
smaller than icon height.
parent 556cf77a
......@@ -42,6 +42,40 @@ StatusBarToolButton::StatusBarToolButton(QWidget* parent)
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
}
QSize StatusBarToolButton::sizeHint() const
{
QSize sizeHint = QToolButton::sizeHint();
QStyleOptionToolButton opt;
initStyleOption(&opt);
const bool isIconOnly = opt.toolButtonStyle == Qt::ToolButtonIconOnly
|| (!opt.icon.isNull() && opt.text.isEmpty());
const bool isTextOnly = opt.toolButtonStyle == Qt::ToolButtonTextOnly
|| (opt.icon.isNull() && !opt.text.isEmpty());
if (isIconOnly || isTextOnly) {
QSize contentSize;
if (isIconOnly) {
contentSize.setHeight(qMax(opt.iconSize.height(), opt.fontMetrics.height()));
contentSize.setWidth(contentSize.height());
} else if (isTextOnly) {
// copying the default text size behavior for text only QToolButtons
QSize textSize = opt.fontMetrics.size(Qt::TextShowMnemonic, opt.text);
// NOTE: QToolButton really does use horizontalAdvance() instead of boundingRect().width()
textSize.setWidth(textSize.width() + opt.fontMetrics.horizontalAdvance(QLatin1Char(' '))*2);
contentSize.setHeight(qMax(opt.iconSize.height(), textSize.height()));
contentSize.setWidth(textSize.width());
}
if (popupMode() == MenuButtonPopup) {
contentSize.setWidth(contentSize.width() + style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this));
}
sizeHint = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, contentSize, this);
}
return sizeHint;
}
void StatusBarToolButton::setGroupPosition(StatusBarToolButton::GroupPosition groupPosition)
{
mGroupPosition = groupPosition;
......
......@@ -48,6 +48,8 @@ public:
explicit StatusBarToolButton(QWidget* parent = nullptr);
QSize sizeHint() const override;
void setGroupPosition(StatusBarToolButton::GroupPosition groupPosition);
protected:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment