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. Text in a QTabBar (QTabWidget) on MacOS and linux

Text in a QTabBar (QTabWidget) on MacOS and linux

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 3 Posters 5.4k 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.
  • S Offline
    S Offline
    stephane78
    wrote on last edited by
    #1

    Hi,
    We have a QTabWidget with tabs with titles in a software.On windows we don't have any problem but on MacOS and linux the titles on QTabBar are too low and outside of the QTabBar (in the pane or frame).
    I have tried tab_widget->setStyleSheet("QTabWidget::tab-bar {height: 30 px ;alignment : top;}"); and tbar->setStyleSheet("height: 30 px ;alignment : top;") (where tbar is the QTabBar) but I don't see the title (text) of the tabs anymore.
    is there a solution (with stylesheet or other) ?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stephane78
      wrote on last edited by
      #2

      Hi,
      I have found a workaround to this first problem but I have another problem with QTabBar on MacOS: the selected tabs are twice larger than in normal state and I want that the selected tabs don't be larger.I don't see an option for that in the stylesheet...

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        What version of OS X and Qt are you running ?

        Can you show a minimal sample code that reproduces this ?

        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
        0
        • S Offline
          S Offline
          stephane78
          wrote on last edited by
          #4

          @SGaist, it's mac os 10.10.4 with Qt5.6.0.I have now just several addTab() for each tab in the QTabWidget.
          I have tried too to add stylesheet for the tabbar with width= but it doesn't do nothing....

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stephane78
            wrote on last edited by
            #5

            @SGaist, is it possible to apply a stylesheet to the QTabBar only by derivating QTabWidget ? I haven't yet tried this way....

            1 Reply Last reply
            0
            • S Offline
              S Offline
              stephane78
              wrote on last edited by
              #6

              @SGaist, derivating QTabWidget and applying a width of bar in a stylesheet doesn't do anything

              1 Reply Last reply
              0
              • S Offline
                S Offline
                stephane78
                wrote on last edited by
                #7

                @SGaist, I have tried to put the width of the scroller and the width of the selected tab in a stylesheet by derivating and not derivating QTabWidget and it is not ok......

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  stephane78
                  wrote on last edited by
                  #8

                  @SGaist, the tabs are too large when they are selected on MacOS, and I couldn't change that with stylesheets or with stylesheets inside a derivated class of Qtabwidget

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Again, can you share a minimal code sample that reproduce that ?

                    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
                    0
                    • S Offline
                      S Offline
                      stephane78
                      wrote on last edited by stephane78
                      #10

                      @SGAist,

                      tabwidget=new QTabWidget();
                      tab1=new QWidget();
                      tab2=new QWidget();
                      tab3=new QWidget();
                      tab4=new QWidget();
                      tab5=new QWidget();
                      tabwidget->clear();
                      
                      inittab1();
                      inittab2();
                      inittab3();
                      inittab4();
                      inittab5();
                      
                      tabwidget->addTab(tab1,"tab1");
                      tabwidget->addTab(tab2,"tab2");
                      tabwidget->addTab(tab3,"tab3");
                      tabwidget->addTab(tab4,"tab4");
                      tabwidget->addTab(tab5,"tab5");
                      

                      where the methods inittab1() put things in the tab frame
                      I don't really see the interest to look at such code.......
                      I have tried too derivating QTabWidget and putting stylesheet to a new QTabBar and putting stylesheet to QTabwidget but it does nothing
                      I haven't any problem under windows with this code, it is ok under windows, so the problem is specific to MacOS version of Qt and perhaps under linux too, but I haven't yet tried with linux

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        The interest of having that code at hand is to be able to reproduce your situation in the same conditions so a minimal version showing the behavior you get is rather useful.

                        OS X and Windows don't have the same GUI guidelines and Qt stays as close as possible of the platform style.

                        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
                        0
                        • S Offline
                          S Offline
                          stephane78
                          wrote on last edited by
                          #12

                          @SGaist, ok, this code is in the constructor of a Qwidget derivated object....

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            stephane78
                            wrote on last edited by
                            #13

                            @SGaist, I have made a linux version of the software with Qt5.6.0 too and there isn't this problem. So it is only a problem with MacOs X.

                            1 Reply Last reply
                            0
                            • R Offline
                              R Offline
                              Rondog
                              wrote on last edited by
                              #14

                              Just to pipe in I have not had problems with QTabWidget on OS X (Qt 5.6.0, OS 10.10.5, XCode 7.2.1).

                              In your sample code I would look at the inittab<n>() functions. Make sure that everything is a child of the widget you are adding to QTabWidet ('tab<n>' in this case). I would suggest something like this to make sure you are not adding controls bypassing the parent:

                              tab1=new QWidget();
                              inittab1(tab1);  // declared as void inittab1(QWidget *parent);
                              tabwidget->addTab(tab1,"tab1");
                              

                              If this is not the problem you need to post some more code. I don't believe it is a problem with QTabWidget. The fact that it may work properly on some OS's and not others doesn't necessarily mean there is no mistakes anywhere.

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                stephane78
                                wrote on last edited by
                                #15

                                we use layouts in these functions so we don't need to specify the parent

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  stephane78
                                  wrote on last edited by
                                  #16

                                  ok the problem is solved:

                                  tabwidget->setStyleSheet("QTabBar::tab {min-width: 7em; min-height: 5ex; padding : 2px;}");
                                  

                                  I should use min-width instead of width, I don't know why, and em and ex units instead of px, but it is ok now....

                                  1 Reply Last reply
                                  0
                                  • R Offline
                                    R Offline
                                    Rondog
                                    wrote on last edited by Rondog
                                    #17

                                    I am not sure how your inittab() function is setup but based on your comment about "using a layout so a parent is not needed" I suspect this is the reason for the problem (or related to the problem somehow).

                                    The stylesheet should only be something you use to alter the default appearance of a widget (not to 'fix' a problem). The widget should always appear properly without the stylesheets.

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      stephane78
                                      wrote on last edited by
                                      #18

                                      when you put all the widgets in layouts and you do at the end of the function :

                                      tab1->setLayout(main_layout);

                                      I don't think that a parent is needed

                                      1 Reply Last reply
                                      0
                                      • R Offline
                                        R Offline
                                        Rondog
                                        wrote on last edited by Rondog
                                        #19

                                        Well, apparently you might need a parent. I use the QTabWidget often without the problems you describe. My main working system is OS X with GNU/Linux second and Windows a distant third (very distant).

                                        My guess would be something related to this control unable to figure out the proper size of the widget since no 'children' of each added tab exists. Usually size problems are from this kind of thing. Size problems could easily mean that text positions will be wrong (?).

                                        This is an example something I have using this control and it works without the need to add a stylesheet or some other 'fix':

                                        	d_tab_widget = new QTabWidget(this); // child of QDialog
                                        
                                        	tab_input_widget = new QWidget(); //  widget used for tab of QTabWidget
                                        	d_tab_widget->addTab(tab_input_widget,QStringLiteral("Input"));
                                        
                                        	// controls that are inside the tab widget of QTabWidget
                                        	tabwidget_gridlayout = new QGridLayout(tab_input_widget); // same as 'setLayout()'
                                        
                                        	select_file_button = new QPushButton(tab_input_widget); // child of parent widget
                                        	select_file_button->setAutoDefault(false);
                                        	tabwidget_gridlayout->addLayout(select_file_button,0,0,1,1);
                                        
                                        	options_button = new QPushButton(tab_input_widget); // child of parent widget
                                        	options_button->setAutoDefault(false);
                                        	tabwidget_gridlayout->addLayout(options_button,1,0,1,1);
                                        
                                        	close_button = new QPushButton(tab_input_widget); // child of parent widget
                                        	close_button->setAutoDefault(false);
                                        	tabwidget_gridlayout->addWidget(close_button,1,1,1,1);
                                        ...
                                        
                                        1 Reply Last reply
                                        0
                                        • S Offline
                                          S Offline
                                          stephane78
                                          wrote on last edited by
                                          #20

                                          ok thanks for your explanation I will try that too

                                          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