From b5d762ae87e8f3a35a84a6c7d6d324c27d487a8c Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 17 Aug 2017 11:31:27 +0200 Subject: 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 --- tests/manual/qtabbar/main.cpp | 12 ++- tests/manual/qtabbar/tabbarform.ui | 159 +++++++++++++++++++------------------ 2 files changed, 94 insertions(+), 77 deletions(-) (limited to 'tests/manual/qtabbar') 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 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::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 @@ 0 0 308 - 260 + 308 @@ -22,24 +22,61 @@ - - + + + + false + + + + North + + + + + South + + + + + West + + + + + East + + + + + + + + Qt::Vertical + + + + 20 + 12 + + + + + + - Right aligned + Tab bar options: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - textAlignmentGroup - - - + + - Left aligned + Document mode - - textAlignmentGroup - @@ -49,14 +86,14 @@ - - + + - Tabs alignment: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Left aligned + + textAlignmentGroup + @@ -66,10 +103,13 @@ - - + + - Document mode + Tab shape (TODO): + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -80,47 +120,17 @@ - - - - false - - - - North - - - - - South - - - - - West - - - - - East - - - - - - - - Qt::Vertical + + + + Tabs alignment: - - - 20 - 12 - + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + - + Qt::Vertical @@ -133,17 +143,14 @@ - - + + - Tab bar options: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Display icon - + Centered @@ -153,20 +160,20 @@ - - + + - Tab shape (TODO): - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Right aligned + + textAlignmentGroup + - - + + - Display icon + Long tab label -- cgit v1.2.3