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

Qt Code:
  1. #include <QApplication>
  2. #include <QtGui>
  3.  
  4. void setStyleSheet();
  5. int main(int argc, char* argv[])
  6. {
  7. QApplication app(argc, argv);
  8. setStyleSheet();
  9. mw.showMaximized();
  10. QTabWidget* tabWidget = new QTabWidget;
  11. QString s = "a";
  12. for (int i = 0; i < 6; i++) tabWidget->addTab(new QWidget(), s += s);
  13. mw.setCentralWidget(tabWidget);
  14. mw.show();
  15. return app.exec();
  16. }
  17.  
  18. void setStyleSheet()
  19. {
  20. QString style;
  21. QTextStream stream(&style);
  22.  
  23. stream << "QTabWidget::pane {"
  24. << "border-top: 2px solid darkgray;"
  25. << "}"
  26. << "QTabBar::tab {"
  27. << "margin-top:3px;"
  28. << "background-color: white;"
  29. << "border: 1px solid darkgray;"
  30. << "margin-left: 2px;"
  31. << "border-top-right-radius: 10%;"
  32. << "border-top-left-radius: 10%;"
  33. << "padding: 5px;"
  34. << "min-width:100px;"
  35. << "max-width:130px;"
  36. << "}";
  37.  
  38. qApp->setStyleSheet(style);
  39. }
To copy to clipboard, switch view to plain text mode