代码:
#include#include #include #include #include class TabWidget : public QTabWidget { public: QTabBar* tabBar() { return QTabWidget::tabBar(); } }; #define Count(arr) ((unsigned int) (sizeof(arr) / sizeof(arr[0]))) int main( int argc, char** argv ) { QApplication app( argc, argv ); TabWidget tw; QWidget w; QStyle::StandardPixmap tab_icons[] = { QStyle::SP_MediaSkipBackward, QStyle::SP_MediaPlay, QStyle::SP_MediaStop, QStyle::SP_MediaSkipForward }; QString tab_names[] = { "Rewind", "Play", "Stop", "Fast Forward" }; tw.setTabPosition( QTabWidget::West ); for( int i = 0; i < Count( tab_icons ); i++ ) { tw.addTab( new QWidget(), QString() ); QToolButton* tb = new QToolButton; tb->setStyleSheet( "background-color: none; border: 0px;" ); tb->setAttribute( Qt::WA_TransparentForMouseEvents ); tb->setIcon( app.style()->standardIcon( tab_icons[i] ) ); tb->setText( tab_names[i] ); tb->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); tw.tabBar()->setTabButton( i, QTabBar::LeftSide, tb ); } tw.show(); return app.exec(); }
界面效果: