diff options
| author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-03-20 22:13:36 +0100 |
|---|---|---|
| committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-21 11:00:38 +0100 |
| commit | 49b6963b40dfa2f0ec9634c71707c70f9842a418 (patch) | |
| tree | 981d4b0b790d4d9d88807b9762e88b375dd291bf /src | |
| parent | 3bf44eb729b5c81125e374ad11aaf6c3e53d5c4a (diff) | |
Fix ToolButton size
Change-Id: Ic84b6422aebc9336132a70594361e5e12c8130f6
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/private/qstyleitem.cpp | 28 | ||||
| -rw-r--r-- | src/styles/Desktop/ToolButtonStyle.qml | 3 |
2 files changed, 25 insertions, 6 deletions
diff --git a/src/private/qstyleitem.cpp b/src/private/qstyleitem.cpp index 5c858c91f..7fd4dabc5 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); diff --git a/src/styles/Desktop/ToolButtonStyle.qml b/src/styles/Desktop/ToolButtonStyle.qml index af3da43c0..e591d129e 100644 --- a/src/styles/Desktop/ToolButtonStyle.qml +++ b/src/styles/Desktop/ToolButtonStyle.qml @@ -54,9 +54,6 @@ Style { hasFocus: control.activeFocus hints: control.styleHints.concat([control.__position]) - contentWidth: 30 - contentHeight: 30 - properties: { "icon": control.__action.__icon } |
