summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Edmundson <davidedmundson@kde.org>2013-12-05 14:47:47 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-09 18:23:48 +0200
commit53fca456b2d5c4d290592846c0a14242ac218e1d (patch)
tree0f3dff7fa2f54c391030e7d714bbfc29b9ef996c
parentd5d31fc8847b65e121300806dea935029766f781 (diff)
downloadqtquickcontrols-53fca456b2d5c4d290592846c0a14242ac218e1d.tar.gz
Take into account icon size when determining button size
When a style calculates the sizeFromContents on a pushbutton it needs to be informed about the size of the icon on the button. In oxygen icons with buttons are slightly larger than buttons without. Change-Id: I2f2d5f08747ad5e6ac0dfb50531c3e7627e9b35f Reviewed-by: Sebastian Kügler <sebas@kde.org> Reviewed-by: Marco Martin <mart@kde.org> Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
-rw-r--r--src/controls/Private/qquickstyleitem.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/controls/Private/qquickstyleitem.cpp b/src/controls/Private/qquickstyleitem.cpp
index 4a90e60b..4da6773a 100644
--- a/src/controls/Private/qquickstyleitem.cpp
+++ b/src/controls/Private/qquickstyleitem.cpp
@@ -936,8 +936,16 @@ QSize QQuickStyleItem::sizeFromContents(int width, int height)
break;
case Button: {
QStyleOptionButton *btn = qstyleoption_cast<QStyleOptionButton*>(m_styleoption);
- int newWidth = qMax(width, btn->fontMetrics.width(btn->text));
- int newHeight = qMax(height, btn->fontMetrics.height());
+
+ int contentWidth = btn->fontMetrics.width(btn->text);
+ int contentHeight = btn->fontMetrics.height();
+ if (!btn->icon.isNull()) {
+ //+4 matches a hardcoded value in QStyle and acts as a margin between the icon and the text.
+ contentWidth += btn->iconSize.width() + 4;
+ contentHeight = qMax(btn->fontMetrics.height(), btn->iconSize.height());
+ }
+ int newWidth = qMax(width, contentWidth);
+ int newHeight = qMax(height, contentHeight);
size = qApp->style()->sizeFromContents(QStyle::CT_PushButton, m_styleoption, QSize(newWidth, newHeight)); }
#ifdef Q_OS_OSX
if (style() == "mac") {