summaryrefslogtreecommitdiff
path: root/src/private
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-03-20 22:13:36 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-21 11:00:38 +0100
commit49b6963b40dfa2f0ec9634c71707c70f9842a418 (patch)
tree981d4b0b790d4d9d88807b9762e88b375dd291bf /src/private
parent3bf44eb729b5c81125e374ad11aaf6c3e53d5c4a (diff)
downloadqtquickcontrols-49b6963b40dfa2f0ec9634c71707c70f9842a418.tar.gz
Fix ToolButton size
Change-Id: Ic84b6422aebc9336132a70594361e5e12c8130f6 Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Diffstat (limited to 'src/private')
-rw-r--r--src/private/qstyleitem.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/private/qstyleitem.cpp b/src/private/qstyleitem.cpp
index 5c858c91..7fd4dabc 100644
--- a/src/private/qstyleitem.cpp
+++ b/src/private/qstyleitem.cpp
@@ -663,9 +663,31 @@ QSize QStyleItem::sizeFromContents(int width, int height)
break;
case ToolButton: {
QStyleOptionToolButton *btn = qstyleoption_cast<QStyleOptionToolButton*>(m_styleoption);
- int newWidth = qMax(width, btn->fontMetrics.width(btn->text));
- int newHeight = qMax(height, btn->fontMetrics.height());
- size = qApp->style()->sizeFromContents(QStyle::CT_ToolButton, m_styleoption, QSize(newWidth, newHeight)); }
+ int w = 0;
+ int h = 0;
+ if (btn->toolButtonStyle != Qt::ToolButtonTextOnly) {
+ QSize icon = btn->iconSize;
+ w = icon.width();
+ h = icon.height();
+ }
+ if (btn->toolButtonStyle != Qt::ToolButtonIconOnly) {
+ QSize textSize = btn->fontMetrics.size(Qt::TextShowMnemonic, text());
+ textSize.setWidth(textSize.width() + btn->fontMetrics.width(QLatin1Char(' '))*2);
+ if (btn->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
+ h += 4 + textSize.height();
+ if (textSize.width() > w)
+ w = textSize.width();
+ } else if (btn->toolButtonStyle == Qt::ToolButtonTextBesideIcon) {
+ w += 4 + textSize.width();
+ if (textSize.height() > h)
+ h = textSize.height();
+ } else { // TextOnly
+ w = textSize.width();
+ h = textSize.height();
+ }
+ }
+ btn->rect.setSize(QSize(w, h));
+ size = qApp->style()->sizeFromContents(QStyle::CT_ToolButton, m_styleoption, QSize(w, h)); }
break;
case Button: {
QStyleOptionButton *btn = qstyleoption_cast<QStyleOptionButton*>(m_styleoption);