Qt界面美化4

代码:

复制代码
#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();
}
 
复制代码

界面效果:

 Qt界面美化4_第1张图片


你可能感兴趣的:(Qt-QSS)