Text in a QTabBar (QTabWidget) on MacOS and linux



  • 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) ?



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


  • Lifetime Qt Champion

    Hi,

    What version of OS X and Qt are you running ?

    Can you show a minimal sample code that reproduces this ?



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



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



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



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



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


  • Lifetime Qt Champion

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



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


  • Lifetime Qt Champion

    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.



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



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



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



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



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



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



  • 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



  • 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);
    ...
    


  • ok thanks for your explanation I will try that too


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.