|
27 | 27 | #include <QtWidgets/QToolTip>
|
28 | 28 | #include <QtWidgets/QTreeView>
|
29 | 29 | #include <QtWidgets/QVBoxLayout>
|
| 30 | +#include <QtWidgets/QProxyStyle> |
30 | 31 |
|
31 | 32 | #include <QtGui/QPainter>
|
32 | 33 | #include <QtGui/QScreen>
|
@@ -94,6 +95,7 @@ private slots:
|
94 | 95 | void task206238_twice();
|
95 | 96 | void transparent();
|
96 | 97 | void proxyStyle();
|
| 98 | + void useProxyandStyleSheetStyleInTabBar(); |
97 | 99 | void dialogButtonBox();
|
98 | 100 | void emptyStyleSheet();
|
99 | 101 | void toolTip_data();
|
@@ -1593,6 +1595,51 @@ void tst_QStyleSheetStyle::proxyStyle()
|
1593 | 1595 | delete newProxy;
|
1594 | 1596 | }
|
1595 | 1597 |
|
| 1598 | +void tst_QStyleSheetStyle::useProxyandStyleSheetStyleInTabBar() |
| 1599 | +{ |
| 1600 | +#ifdef Q_OS_MACOS |
| 1601 | + // Since macOS style doesn't support tabbar scroll buttons, skip this case |
| 1602 | + QSKIP("TabBar doesn't support scroll button in macOS"); |
| 1603 | +#endif |
| 1604 | + |
| 1605 | + class CustomProxy : public QProxyStyle |
| 1606 | + { |
| 1607 | + public: |
| 1608 | + QRect subElementRect(SubElement subElement, |
| 1609 | + const QStyleOption *option, |
| 1610 | + const QWidget *widget) const override { |
| 1611 | + auto r = QProxyStyle::subElementRect(subElement, option, widget); |
| 1612 | + if (subElement == SE_TabBarScrollLeftButton) |
| 1613 | + r.moveLeft(0); |
| 1614 | + return r; |
| 1615 | + } |
| 1616 | + }; |
| 1617 | + |
| 1618 | + qApp->setStyleSheet("QTabBar::scroller { width: 50px; }"); |
| 1619 | + |
| 1620 | + QTabBar tabBar; |
| 1621 | + tabBar.setMaximumWidth(150); |
| 1622 | + tabBar.setStyle(new CustomProxy); |
| 1623 | + int totalWidth = 0; |
| 1624 | + for (int tabIndex = 0; tabIndex < 10; ++tabIndex) { |
| 1625 | + tabBar.addTab("Tab " + QString::number(tabIndex)); |
| 1626 | + totalWidth += tabBar.tabRect(tabIndex).width(); |
| 1627 | + } |
| 1628 | + if (totalWidth < 200) |
| 1629 | + tabBar.resize(totalWidth / 2, 30); |
| 1630 | + tabBar.show(); |
| 1631 | + QVERIFY(QTest::qWaitForWindowActive(&tabBar)); |
| 1632 | + |
| 1633 | + QToolButton *scrollLeftButton = qobject_cast<QToolButton *>(tabBar.children().at(0)); |
| 1634 | + QVERIFY(scrollLeftButton); |
| 1635 | + QCOMPARE(scrollLeftButton->pos(), QPoint(0, 0)); |
| 1636 | + QCOMPARE(scrollLeftButton->width(), 25); |
| 1637 | + |
| 1638 | + QToolButton *scrollRightButton = qobject_cast<QToolButton *>(tabBar.children().at(1)); |
| 1639 | + QVERIFY(scrollRightButton); |
| 1640 | + QCOMPARE(scrollRightButton->width(), 25); |
| 1641 | +} |
| 1642 | + |
1596 | 1643 | void tst_QStyleSheetStyle::dialogButtonBox()
|
1597 | 1644 | {
|
1598 | 1645 | QDialogButtonBox box;
|
|
0 commit comments