QTabBar: fix expanded tabs appearance
Fix regression introduced by 175f33ed8. 'expanding' property set to true was ignored when QStyle::styleHint() returned Qt::AlignRight for SH_TabBar_Alignment. When we calculate tabs geometry, we put an empty tab at the front and back and set its expansive attribute depending on tab alignment AND 'expanding' property. Task-number: QTBUG-61480 Change-Id: I6a1827ae8a3f2c6bee5124c18c7f2b1c0a7862f3 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
This commit is contained in:
parent
ffe8884ac3
commit
6e9d24212d
@ -447,9 +447,10 @@ void QTabBarPrivate::layoutTabs()
|
|||||||
QVector<QLayoutStruct> tabChain(tabList.count() + 2);
|
QVector<QLayoutStruct> tabChain(tabList.count() + 2);
|
||||||
|
|
||||||
// We put an empty item at the front and back and set its expansive attribute
|
// We put an empty item at the front and back and set its expansive attribute
|
||||||
// depending on tabAlignment.
|
// depending on tabAlignment and expanding.
|
||||||
tabChain[tabChainIndex].init();
|
tabChain[tabChainIndex].init();
|
||||||
tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignLeft)
|
tabChain[tabChainIndex].expansive = (!expanding)
|
||||||
|
&& (tabAlignment != Qt::AlignLeft)
|
||||||
&& (tabAlignment != Qt::AlignJustify);
|
&& (tabAlignment != Qt::AlignJustify);
|
||||||
tabChain[tabChainIndex].empty = true;
|
tabChain[tabChainIndex].empty = true;
|
||||||
++tabChainIndex;
|
++tabChainIndex;
|
||||||
@ -514,13 +515,12 @@ void QTabBarPrivate::layoutTabs()
|
|||||||
maxExtent = maxWidth;
|
maxExtent = maxWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!expanding) {
|
// Mirror our front item.
|
||||||
// Mirror our front item.
|
tabChain[tabChainIndex].init();
|
||||||
tabChain[tabChainIndex].init();
|
tabChain[tabChainIndex].expansive = (!expanding)
|
||||||
tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignRight)
|
&& (tabAlignment != Qt::AlignRight)
|
||||||
&& (tabAlignment != Qt::AlignJustify);
|
&& (tabAlignment != Qt::AlignJustify);
|
||||||
tabChain[tabChainIndex].empty = true;
|
tabChain[tabChainIndex].empty = true;
|
||||||
}
|
|
||||||
Q_ASSERT(tabChainIndex == tabChain.count() - 1); // add an assert just to make sure.
|
Q_ASSERT(tabChainIndex == tabChain.count() - 1); // add an assert just to make sure.
|
||||||
|
|
||||||
// Do the calculation
|
// Do the calculation
|
||||||
|
@ -56,12 +56,28 @@
|
|||||||
#include <QLayout>
|
#include <QLayout>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
|
#include <QProxyStyle>
|
||||||
|
|
||||||
|
class MyProxyStyle : public QProxyStyle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int styleHint(StyleHint hint, const QStyleOption *option = 0,
|
||||||
|
const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const
|
||||||
|
{
|
||||||
|
if (hint == QStyle::SH_TabBar_Alignment)
|
||||||
|
return Qt::AlignLeft;
|
||||||
|
// return Qt::AlignRight;
|
||||||
|
// return Qt::AlignCenter;
|
||||||
|
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const int TabCount = 5;
|
const int TabCount = 5;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
app.setStyle(new MyProxyStyle);
|
||||||
|
|
||||||
QWidget widget;
|
QWidget widget;
|
||||||
QStackedWidget stackedWidget;
|
QStackedWidget stackedWidget;
|
||||||
@ -69,7 +85,7 @@ int main(int argc, char *argv[])
|
|||||||
tabBar.setDocumentMode(true);
|
tabBar.setDocumentMode(true);
|
||||||
tabBar.setTabsClosable(true);
|
tabBar.setTabsClosable(true);
|
||||||
tabBar.setMovable(true);
|
tabBar.setMovable(true);
|
||||||
tabBar.setExpanding(true);
|
tabBar.setExpanding(false);
|
||||||
|
|
||||||
// top
|
// top
|
||||||
tabBar.setShape(QTabBar::RoundedNorth);
|
tabBar.setShape(QTabBar::RoundedNorth);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user