Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Left align TabBar on Mac OSX
QtWS25 Last Chance

Left align TabBar on Mac OSX

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Taytoo
    wrote on 22 Apr 2019, 03:11 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Apr 2019, 20:23 last edited by
      #2

      Hi,

      Out of curiosity, why are you going against the macOS styling guidelines ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply 23 Apr 2019, 00:27
      1
      • S SGaist
        22 Apr 2019, 20:23

        Hi,

        Out of curiosity, why are you going against the macOS styling guidelines ?

        T Offline
        T Offline
        Taytoo
        wrote on 23 Apr 2019, 00:27 last edited by
        #3

        @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?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 23 Apr 2019, 20:47 last edited by
          #4

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply 24 Apr 2019, 05:03
          1
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 23 Apr 2019, 21:03 last edited by
            #5

            Hi
            try

            QTabWidget::tab-bar {
                left: 0; 
            }
            
            1 Reply Last reply
            0
            • S SGaist
              23 Apr 2019, 20:47

              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 ?

              T Offline
              T Offline
              Taytoo
              wrote on 24 Apr 2019, 05:03 last edited by
              #6

              @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
              try

              QTabWidget::tab-bar {
                  left: 0; 
              }
              

              Not working :(

              M 1 Reply Last reply 24 Apr 2019, 10:10
              0
              • T Taytoo
                24 Apr 2019, 05:03

                @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
                try

                QTabWidget::tab-bar {
                    left: 0; 
                }
                

                Not working :(

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 24 Apr 2019, 10:10 last edited by
                #7

                @Taytoo
                ok then i assume stylesheets cannot do it on OSX.

                T 1 Reply Last reply 25 Apr 2019, 02:44
                0
                • M mrjj
                  24 Apr 2019, 10:10

                  @Taytoo
                  ok then i assume stylesheets cannot do it on OSX.

                  T Offline
                  T Offline
                  Taytoo
                  wrote on 25 Apr 2019, 02:44 last edited by
                  #8

                  @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?

                  M 1 Reply Last reply 25 Apr 2019, 08:36
                  0
                  • T Taytoo
                    25 Apr 2019, 02:44

                    @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?

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 25 Apr 2019, 08:36 last edited by
                    #9

                    @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.

                    T 1 Reply Last reply 21 Mar 2020, 14:51
                    2
                    • M mrjj
                      25 Apr 2019, 08:36

                      @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.

                      T Offline
                      T Offline
                      Taytoo
                      wrote on 21 Mar 2020, 14:51 last edited by
                      #10

                      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

                      S M 2 Replies Last reply 21 Mar 2020, 20:31
                      0
                      • T Taytoo
                        21 Mar 2020, 14:51

                        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

                        S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 21 Mar 2020, 20:31 last edited by
                        #11

                        @Taytoo hi, did you check the link provided by @mrjj ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        1
                        • T Taytoo
                          21 Mar 2020, 14:51

                          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

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 21 Mar 2020, 20:34 last edited by mrjj
                          #12

                          @Taytoo
                          Hi

                          In 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.

                          T 1 Reply Last reply 22 Mar 2020, 13:48
                          1
                          • M mrjj
                            21 Mar 2020, 20:34

                            @Taytoo
                            Hi

                            In 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.

                            T Offline
                            T Offline
                            Taytoo
                            wrote on 22 Mar 2020, 13:48 last edited by
                            #13

                            @mrjj That's what I read online on stackoverflow as well and that particular author suggested modifying qt sources and rebuilding, but i don't know how to do this.

                            Anyone has any idea why qproxystyle isn't working?

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved