diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2017-08-17 11:31:27 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2017-08-18 07:27:52 +0000 |
commit | b5d762ae87e8f3a35a84a6c7d6d324c27d487a8c (patch) | |
tree | 2701db995a0e30d3e05fba0ce7989b80978a3028 | |
parent | 362466c7d2e12c4587d5de1eb51cd537be9f7e2b (diff) |
macOS: Fix padding around tab label with icon
Change c12072c685f7e93d5b84e289ca23106482379eff fixed a problem
where tab labels would overlap with the icons if the tab became
too small to contain the text. But it did not properly account
for the full area occupied by the icon, because the horizontal
padding is hardcoded to 4 in the mac style, whereas in the
common style (where the icon is drawn) it uses the pixel metric
for this.
In addition, the change only allocated space on the left side,
causing the label to no longer be centered.
Task-number: QTBUG-61235
Change-Id: Ieec4f7044584361f92045addbc8bbd81bd5c9fc7
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
-rw-r--r-- | src/widgets/styles/qmacstyle_mac.mm | 7 | ||||
-rw-r--r-- | tests/manual/qtabbar/main.cpp | 12 | ||||
-rw-r--r-- | tests/manual/qtabbar/tabbarform.ui | 159 |
3 files changed, 100 insertions, 78 deletions
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index b5d1fff5e7..d9eeb2c83b 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -1142,7 +1142,12 @@ void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widg tabIconSize.width(), tabIconSize.height()); if (!verticalTabs) *iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect); - tr.setLeft(tr.left() + tabIconSize.width() + 4); + + int stylePadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2; + stylePadding -= hpadding; + + tr.setLeft(tr.left() + stylePadding + tabIconSize.width() + 4); + tr.setRight(tr.right() - stylePadding - tabIconSize.width() - 4); } if (!verticalTabs) diff --git a/tests/manual/qtabbar/main.cpp b/tests/manual/qtabbar/main.cpp index 466a7e20fc..82bcd838e6 100644 --- a/tests/manual/qtabbar/main.cpp +++ b/tests/manual/qtabbar/main.cpp @@ -103,6 +103,9 @@ int main(int argc, char *argv[]) // right // tabBar.setShape(QTabBar::RoundedEast); + const auto shortLabel = QStringLiteral("Tab %1"); + const auto longLabel = QStringLiteral("An Extremely Long Tab Label %1"); + QMap<int, QWidget*> tabs; for (int i = 0; i < TabCount; i++) { QString tabNumberString = QString::number(i); @@ -110,7 +113,7 @@ int main(int argc, char *argv[]) tabs[i] = label; label->setAlignment(Qt::AlignCenter); stackedWidget.addWidget(label); - tabBar.addTab(QStringLiteral("Tab %1").arg(tabNumberString)); + tabBar.addTab(shortLabel.arg(tabNumberString)); } QObject::connect(&tabBar, &QTabBar::tabMoved, [&tabs](int from, int to) { @@ -205,6 +208,13 @@ int main(int argc, char *argv[]) tabBar.setTabIcon(i, icon); }); + form.ui->longLabelButton->setChecked(false); + QObject::connect(form.ui->longLabelButton, &QCheckBox::toggled, [&] { + const auto &label = form.ui->longLabelButton->isChecked() ? longLabel : shortLabel; + for (int i = 0; i < tabBar.count(); i++) + tabBar.setTabText(i, label.arg(i)); + }); + QObject::connect(form.ui->shapeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [&](int index) { Q_UNUSED(index); // TODO diff --git a/tests/manual/qtabbar/tabbarform.ui b/tests/manual/qtabbar/tabbarform.ui index 17100b3b62..f8766f22f2 100644 --- a/tests/manual/qtabbar/tabbarform.ui +++ b/tests/manual/qtabbar/tabbarform.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>308</width> - <height>260</height> + <height>308</height> </rect> </property> <property name="sizePolicy"> @@ -22,24 +22,61 @@ <layout class="QGridLayout" name="gridLayout_2"> <item row="0" column="0"> <layout class="QGridLayout" name="gridLayout"> - <item row="10" column="1"> - <widget class="QRadioButton" name="rightAlignedButton"> + <item row="7" column="1"> + <widget class="QComboBox" name="shapeComboBox"> + <property name="enabled"> + <bool>false</bool> + </property> + <item> + <property name="text"> + <string>North</string> + </property> + </item> + <item> + <property name="text"> + <string>South</string> + </property> + </item> + <item> + <property name="text"> + <string>West</string> + </property> + </item> + <item> + <property name="text"> + <string>East</string> + </property> + </item> + </widget> + </item> + <item row="8" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>12</height> + </size> + </property> + </spacer> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label_2"> <property name="text"> - <string>Right aligned</string> + <string>Tab bar options:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> - <attribute name="buttonGroup"> - <string notr="true">textAlignmentGroup</string> - </attribute> </widget> </item> - <item row="8" column="1"> - <widget class="QRadioButton" name="leftAlignedButton"> + <item row="0" column="1"> + <widget class="QCheckBox" name="documentModeButton"> <property name="text"> - <string>Left aligned</string> + <string>Document mode</string> </property> - <attribute name="buttonGroup"> - <string notr="true">textAlignmentGroup</string> - </attribute> </widget> </item> <item row="2" column="1"> @@ -49,14 +86,14 @@ </property> </widget> </item> - <item row="8" column="0"> - <widget class="QLabel" name="label"> + <item row="9" column="1"> + <widget class="QRadioButton" name="leftAlignedButton"> <property name="text"> - <string>Tabs alignment:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + <string>Left aligned</string> </property> + <attribute name="buttonGroup"> + <string notr="true">textAlignmentGroup</string> + </attribute> </widget> </item> <item row="1" column="1"> @@ -66,10 +103,13 @@ </property> </widget> </item> - <item row="0" column="1"> - <widget class="QCheckBox" name="documentModeButton"> + <item row="7" column="0"> + <widget class="QLabel" name="label_3"> <property name="text"> - <string>Document mode</string> + <string>Tab shape (TODO):</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> @@ -80,47 +120,17 @@ </property> </widget> </item> - <item row="6" column="1"> - <widget class="QComboBox" name="shapeComboBox"> - <property name="enabled"> - <bool>false</bool> - </property> - <item> - <property name="text"> - <string>North</string> - </property> - </item> - <item> - <property name="text"> - <string>South</string> - </property> - </item> - <item> - <property name="text"> - <string>West</string> - </property> - </item> - <item> - <property name="text"> - <string>East</string> - </property> - </item> - </widget> - </item> - <item row="7" column="0"> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> + <item row="9" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Tabs alignment:</string> </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>12</height> - </size> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> - </spacer> + </widget> </item> - <item row="5" column="1"> + <item row="6" column="1"> <spacer name="verticalSpacer_2"> <property name="orientation"> <enum>Qt::Vertical</enum> @@ -133,17 +143,14 @@ </property> </spacer> </item> - <item row="0" column="0"> - <widget class="QLabel" name="label_2"> + <item row="4" column="1"> + <widget class="QCheckBox" name="displayIconButton"> <property name="text"> - <string>Tab bar options:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + <string>Display icon</string> </property> </widget> </item> - <item row="9" column="1"> + <item row="10" column="1"> <widget class="QRadioButton" name="centeredButton"> <property name="text"> <string>Centered</string> @@ -153,20 +160,20 @@ </attribute> </widget> </item> - <item row="6" column="0"> - <widget class="QLabel" name="label_3"> + <item row="11" column="1"> + <widget class="QRadioButton" name="rightAlignedButton"> <property name="text"> - <string>Tab shape (TODO):</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + <string>Right aligned</string> </property> + <attribute name="buttonGroup"> + <string notr="true">textAlignmentGroup</string> + </attribute> </widget> </item> - <item row="4" column="1"> - <widget class="QCheckBox" name="displayIconButton"> + <item row="5" column="1"> + <widget class="QCheckBox" name="longLabelButton"> <property name="text"> - <string>Display icon</string> + <string>Long tab label</string> </property> </widget> </item> |