From 3fa4ed19cbe54d565fbe435a185d411e978e90d7 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich <gabriel.dedietrich@digia.com> Date: Fri, 29 Mar 2013 12:11:49 +0100 Subject: [PATCH] Button: Remove extra margins on Mac Ideally, we would fix that in QMacStyle, but it's too much of a change in the style right now. The values have been choosen to look good with ComboBox, which is the other button shaped control. Gallery example updated with 'right' sizes for buttons in first tab. Change-Id: I331eff4930b22cf4b42cdbd6b3191fff403ddae3 Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com> --- examples/gallery/content/Controls.qml | 4 ++-- src/private/qstyleitem.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/gallery/content/Controls.qml b/examples/gallery/content/Controls.qml index c0c1ff585..7650cab10 100644 --- a/examples/gallery/content/Controls.qml +++ b/examples/gallery/content/Controls.qml @@ -66,13 +66,13 @@ Item { Button { id: button1 text: "Button 1" - width: 96 + width: 97 tooltip:"This is an interesting tool tip" } Button { id:button2 text:"Button 2" - width:96 + width:97 } } ComboBox { diff --git a/src/private/qstyleitem.cpp b/src/private/qstyleitem.cpp index 58827316e..122704984 100644 --- a/src/private/qstyleitem.cpp +++ b/src/private/qstyleitem.cpp @@ -721,6 +721,12 @@ QSize QStyleItem::sizeFromContents(int width, int height) int newWidth = qMax(width, btn->fontMetrics.width(btn->text)); int newHeight = qMax(height, btn->fontMetrics.height()); size = qApp->style()->sizeFromContents(QStyle::CT_PushButton, m_styleoption, QSize(newWidth, newHeight)); } +#ifdef Q_OS_MAC + if (style() == "mac") { + // Cancel out QMacStylePrivate::PushButton*Offset, or part of it + size -= QSize(7, 6); + } +#endif break; case ComboBox: { QStyleOptionComboBox *btn = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption); @@ -1063,6 +1069,12 @@ void QStyleItem::paint(QPainter *painter) switch (m_itemType) { case Button: +#ifdef Q_OS_MAC + if (style() == "mac") { + // Add back what was substracted in sizeFromContents() + m_styleoption->rect.adjust(-4, -2, 3, 4); + } +#endif qApp->style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter); break; case ItemRow :{ -- GitLab