Left align TabBar on Mac OSX
-
I've styled a TabBar using stylesheet and for consistency across platforms, I want it aligned on the left-side. I've tried all stylesheet options that I found online but none seems to work on Mac.
Came across this: link. Looks like its not possible through stylesheets? Is that still true?
-
Hi,
Out of curiosity, why are you going against the macOS styling guidelines ?
-
@SGaist Its a completely custom UI, doesn't use any native looking components on any platform. Even the tabs don't have the typical "Tab" look to them, so I wanted to keep the UI look consistent across platforms.
Would there be any issues with Apple approval?
-
I can't comment on that.
It was really curiosity about your use case.
Might be a silly question but did you already checked the QTabBar part of the style sheet documentation ?
-
Hi
tryQTabWidget::tab-bar { left: 0; }
-
I can't comment on that.
It was really curiosity about your use case.
Might be a silly question but did you already checked the QTabBar part of the style sheet documentation ?
@SGaist said in Left align TabBar on Mac OSX:
Might be a silly question but did you already checked the QTabBar part of the style sheet documentation ?
Yes, I tried all the options and they are working on Windows. Not on Mac though
@mrjj said in Left align TabBar on Mac OSX:
Hi
tryQTabWidget::tab-bar { left: 0; }
Not working :(
-
@SGaist said in Left align TabBar on Mac OSX:
Might be a silly question but did you already checked the QTabBar part of the style sheet documentation ?
Yes, I tried all the options and they are working on Windows. Not on Mac though
@mrjj said in Left align TabBar on Mac OSX:
Hi
tryQTabWidget::tab-bar { left: 0; }
Not working :(
-
@mrjj The suggestion give in the stackoverflow answer i.e. use QStyle, how would that work? if I have stylesheet applied to the Tab, would QStyle conflict with it?
@Taytoo
Hi
The QStyle is the backbone of drawing the widgets. It does respect stylesheets in most cases.There is also https://doc.qt.io/qt-5/qproxystyle.html
which is often used for this kind of override.Its something like
https://stackoverflow.com/questions/29835759/qt-custom-qstyle-for-qtabbar
but its not full sample you have to fiddle with it to get it to move the actual tab positions. -
@Taytoo
Hi
The QStyle is the backbone of drawing the widgets. It does respect stylesheets in most cases.There is also https://doc.qt.io/qt-5/qproxystyle.html
which is often used for this kind of override.Its something like
https://stackoverflow.com/questions/29835759/qt-custom-qstyle-for-qtabbar
but its not full sample you have to fiddle with it to get it to move the actual tab positions. -
Can anyone provide an example of how to use QProxyStyle to set tab alignment to left on macOS? I've never worked with QProxyStyle so finding it hard to figure this stuff out, even from documentation
-
Can anyone provide an example of how to use QProxyStyle to set tab alignment to left on macOS? I've never worked with QProxyStyle so finding it hard to figure this stuff out, even from documentation
@Taytoo
HiIn theory, we should be able to do
class TabStyle : public QProxyStyle { public: explicit TabStyle(Qt::Orientation orientation, QStyle *baseStyle = 0) : QProxyStyle(baseStyle) {} virtual int styleHint(StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const override { if (stylehint == SH_TabBar_Alignment ) return Qt::AlignLeft; // or right return QProxyStyle::styleHint(stylehint, opt, widget, returnData); } };
However, i could not get it to RIGHT align on Windows so it seems Tabbar ignores it.
https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qtabbar.cpp.html
It goes
void QTabBarPrivate::layoutTabs() { Q_Q(QTabBar); .... Qt::Alignment tabAlignment = Qt::Alignment(q->style()->styleHint(QStyle::SH_TabBar_Alignment, 0, q));
So it seems it should use the hint but my styleHint seems not to have any effect on
the tab alignment at all.
(always left, regardless of center or right)So im a bit lost but Im using a tab widget and maybe its the reason it get ignored but
as far as i know, it's using a tabbar internally. -
@Taytoo
HiIn theory, we should be able to do
class TabStyle : public QProxyStyle { public: explicit TabStyle(Qt::Orientation orientation, QStyle *baseStyle = 0) : QProxyStyle(baseStyle) {} virtual int styleHint(StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const override { if (stylehint == SH_TabBar_Alignment ) return Qt::AlignLeft; // or right return QProxyStyle::styleHint(stylehint, opt, widget, returnData); } };
However, i could not get it to RIGHT align on Windows so it seems Tabbar ignores it.
https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qtabbar.cpp.html
It goes
void QTabBarPrivate::layoutTabs() { Q_Q(QTabBar); .... Qt::Alignment tabAlignment = Qt::Alignment(q->style()->styleHint(QStyle::SH_TabBar_Alignment, 0, q));
So it seems it should use the hint but my styleHint seems not to have any effect on
the tab alignment at all.
(always left, regardless of center or right)So im a bit lost but Im using a tab widget and maybe its the reason it get ignored but
as far as i know, it's using a tabbar internally.