View Full Version : StyleSheets/QTabBar -- max-width property not respected.

15th November 2007, 01:47
I want to restrict the min- and max-width of a Tab in a QTabBar to a certain range. The min-width property is being respected whereas the max-width property is being ignored. The docs list a bunch of widgets that support these properties and the list is identical for both. QTabBar is not explicitly listed but elsewhere in the docs min-width is being used to set the min-width of a QTabBar. Thus one would assume that QTabBar is able to support both properties. I want the text to be elided if the size exceeds the max-width value. I can use elidedText() but using stylesheets would be way more convenient.
Any ideas?

Thanx in advance

#include <QApplication>
#include <QtGui>

void setStyleSheet();
int main(int argc, char* argv[])
QApplication app(argc, argv);
QMainWindow mw;
QTabWidget* tabWidget = new QTabWidget;
QString s = "a";
for (int i = 0; i < 6; i++) tabWidget->addTab(new QWidget(), s += s);
return app.exec();

void setStyleSheet()
QString style;
QTextStream stream(&style);

stream << "QTabWidget::pane {"
<< "border-top: 2px solid darkgray;"
<< "}"
<< "QTabBar::tab {"
<< "margin-top:3px;"
<< "background-color: white;"
<< "border: 1px solid darkgray;"
<< "margin-left: 2px;"
<< "border-top-right-radius: 10%;"
<< "border-top-left-radius: 10%;"
<< "padding: 5px;"
<< "min-width:100px;"
<< "max-width:130px;"
<< "}";


22nd November 2007, 11:25
If QTabBar isn't listed then I suspect there is a reason for that.