#include <QtGui/QTabBar>class MyTabBar : public QTabBar { Q_OBJECTpublic: explicit MyTabBar( QWidget *parent = 0 ) : QTabBar( parent ) { setExpanding( false ); }private: void paintEvent(QPaintEvent *event) { const int spacing = 2; int tabWidth = width() / count() - spacing; setStyleSheet( QString( "QTabBar::tab { width: %1px; }" ).arg( tabWidth ) ); QTabBar::paintEvent( event ); }};
bool TabBar::event(QEvent *event){ if (event->type() == QEvent::Polish) cachedHeight = -1; return QTabBar::event(event);}QSize TabBar::tabSizeHint(int index) const{ if (cachedHeight == -1) cachedHeight = QTabBar::tabSizeHint(index).height(); return QSize(qBound(100, width()/count(), 200), cachedHeight);}