From 8dd8090f5f5c4bfddef87d9244a353f42ddf9db4 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 27 Aug 2009 14:50:13 +0200 Subject: QTabBar: fix text being croped when there is an icon on the tab By making sure the computation in QTabBar::tabSizeHint and QCommonStylePrivate::tabLayout are the same Reviewed-by: jbache --- src/gui/styles/qcommonstyle.cpp | 22 +++++++--------------- src/gui/widgets/qtabbar.cpp | 9 +++++---- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index ccdce28..9dee6eb 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -1194,6 +1194,11 @@ void QCommonStylePrivate::tabLayout(const QStyleOptionTabV3 *opt, const QWidget tr.setLeft(tr.left() + 6 + 2 + (verticalTabs ? opt->leftButtonSize.height() : opt->leftButtonSize.width())); } + // right widget + if (!opt->rightButtonSize.isEmpty()) { + tr.setRight(tr.right() - 6 - 2 - + (verticalTabs ? opt->rightButtonSize.height() : opt->rightButtonSize.width())); + } // icon if (!opt->icon.isNull()) { @@ -1206,24 +1211,11 @@ void QCommonStylePrivate::tabLayout(const QStyleOptionTabV3 *opt, const QWidget (opt->state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled, (opt->state & QStyle::State_Selected) ? QIcon::On : QIcon::Off ); - int left = opt->rect.left(); - int offset = 4; - if (opt->leftButtonSize.isEmpty()) - offset += 2; - else - left += opt->leftButtonSize.width() + (6 + 2) + 2; - - *iconRect = QRect(left + offset, tr.center().y() - tabIconSize.height() / 2, + *iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2, tabIconSize.width(), tabIconSize .height()); if (!verticalTabs) *iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect); - tr.setLeft(tr.left() + tabIconSize.width() + offset + 2); - } - - // right widget - if (!opt->rightButtonSize.isEmpty()) { - tr.setRight(tr.right() - 6 - 2 - - (verticalTabs ? opt->rightButtonSize.height() : opt->rightButtonSize.width())); + tr.setLeft(tr.left() + tabIconSize.width() + 4); } if (!verticalTabs) diff --git a/src/gui/widgets/qtabbar.cpp b/src/gui/widgets/qtabbar.cpp index d8246c8..f3775c2 100644 --- a/src/gui/widgets/qtabbar.cpp +++ b/src/gui/widgets/qtabbar.cpp @@ -1293,6 +1293,7 @@ QSize QTabBarPrivate::minimumTabSizeHint(int index) */ QSize QTabBar::tabSizeHint(int index) const { + //Note: this must match with the computations in QCommonStylePrivate::tabLayout Q_D(const QTabBar); if (const QTabBarPrivate::Tab *tab = d->at(index)) { QStyleOptionTabV3 opt; @@ -1309,18 +1310,18 @@ QSize QTabBar::tabSizeHint(int index) const int widgetWidth = 0; int widgetHeight = 0; int padding = 0; - if (opt.leftButtonSize.isValid()) { + if (!opt.leftButtonSize.isEmpty()) { padding += 6 + 2; widgetWidth += opt.leftButtonSize.width(); widgetHeight += opt.leftButtonSize.height(); } - if (opt.rightButtonSize.isValid()) { + if (!opt.rightButtonSize.isEmpty()) { padding += 6 + 2; widgetWidth += opt.rightButtonSize.width(); widgetHeight += opt.rightButtonSize.height(); } - if (opt.iconSize.isValid()) - padding += 2; + if (!opt.icon.isNull()) + padding += 4; QSize csz; if (verticalTabs(d->shape)) { -- cgit v0.12