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>
This commit is contained in:
parent
362466c7d2
commit
b5d762ae87
@ -1142,7 +1142,12 @@ void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widg
|
|||||||
tabIconSize.width(), tabIconSize.height());
|
tabIconSize.width(), tabIconSize.height());
|
||||||
if (!verticalTabs)
|
if (!verticalTabs)
|
||||||
*iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect);
|
*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)
|
if (!verticalTabs)
|
||||||
|
@ -103,6 +103,9 @@ int main(int argc, char *argv[])
|
|||||||
// right
|
// right
|
||||||
// tabBar.setShape(QTabBar::RoundedEast);
|
// tabBar.setShape(QTabBar::RoundedEast);
|
||||||
|
|
||||||
|
const auto shortLabel = QStringLiteral("Tab %1");
|
||||||
|
const auto longLabel = QStringLiteral("An Extremely Long Tab Label %1");
|
||||||
|
|
||||||
QMap<int, QWidget*> tabs;
|
QMap<int, QWidget*> tabs;
|
||||||
for (int i = 0; i < TabCount; i++) {
|
for (int i = 0; i < TabCount; i++) {
|
||||||
QString tabNumberString = QString::number(i);
|
QString tabNumberString = QString::number(i);
|
||||||
@ -110,7 +113,7 @@ int main(int argc, char *argv[])
|
|||||||
tabs[i] = label;
|
tabs[i] = label;
|
||||||
label->setAlignment(Qt::AlignCenter);
|
label->setAlignment(Qt::AlignCenter);
|
||||||
stackedWidget.addWidget(label);
|
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) {
|
QObject::connect(&tabBar, &QTabBar::tabMoved, [&tabs](int from, int to) {
|
||||||
@ -205,6 +208,13 @@ int main(int argc, char *argv[])
|
|||||||
tabBar.setTabIcon(i, icon);
|
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) {
|
QObject::connect(form.ui->shapeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [&](int index) {
|
||||||
Q_UNUSED(index);
|
Q_UNUSED(index);
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>308</width>
|
<width>308</width>
|
||||||
<height>260</height>
|
<height>308</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -22,65 +22,7 @@
|
|||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="10" column="1">
|
<item row="7" column="1">
|
||||||
<widget class="QRadioButton" name="rightAlignedButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Right aligned</string>
|
|
||||||
</property>
|
|
||||||
<attribute name="buttonGroup">
|
|
||||||
<string notr="true">textAlignmentGroup</string>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="8" column="1">
|
|
||||||
<widget class="QRadioButton" name="leftAlignedButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Left aligned</string>
|
|
||||||
</property>
|
|
||||||
<attribute name="buttonGroup">
|
|
||||||
<string notr="true">textAlignmentGroup</string>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QCheckBox" name="closableTabsButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Closable tabs</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="8" column="0">
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Tabs alignment:</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QCheckBox" name="movableTabsButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Movable tabs</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QCheckBox" name="documentModeButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Document mode</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QCheckBox" name="expandingTabsButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Expanding</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="1">
|
|
||||||
<widget class="QComboBox" name="shapeComboBox">
|
<widget class="QComboBox" name="shapeComboBox">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
@ -107,7 +49,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0">
|
<item row="8" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -120,19 +62,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="1">
|
|
||||||
<spacer name="verticalSpacer_2">
|
|
||||||
<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">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -143,17 +72,38 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="9" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QRadioButton" name="centeredButton">
|
<widget class="QCheckBox" name="documentModeButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Centered</string>
|
<string>Document mode</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QCheckBox" name="closableTabsButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Closable tabs</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="9" column="1">
|
||||||
|
<widget class="QRadioButton" name="leftAlignedButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Left aligned</string>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="buttonGroup">
|
<attribute name="buttonGroup">
|
||||||
<string notr="true">textAlignmentGroup</string>
|
<string notr="true">textAlignmentGroup</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0">
|
<item row="1" column="1">
|
||||||
|
<widget class="QCheckBox" name="movableTabsButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Movable tabs</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="0">
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Tab shape (TODO):</string>
|
<string>Tab shape (TODO):</string>
|
||||||
@ -163,6 +113,36 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QCheckBox" name="expandingTabsButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Expanding</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="9" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Tabs alignment:</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="1">
|
||||||
|
<spacer name="verticalSpacer_2">
|
||||||
|
<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="4" column="1">
|
<item row="4" column="1">
|
||||||
<widget class="QCheckBox" name="displayIconButton">
|
<widget class="QCheckBox" name="displayIconButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -170,6 +150,33 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="10" column="1">
|
||||||
|
<widget class="QRadioButton" name="centeredButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Centered</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="buttonGroup">
|
||||||
|
<string notr="true">textAlignmentGroup</string>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="11" column="1">
|
||||||
|
<widget class="QRadioButton" name="rightAlignedButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Right aligned</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="buttonGroup">
|
||||||
|
<string notr="true">textAlignmentGroup</string>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QCheckBox" name="longLabelButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Long tab label</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user