Text in a QTabBar (QTabWidget) on MacOS and linux
-
Again, can you share a minimal code sample that reproduce that ?
-
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 -
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