Qt界面美化4

代码:

复制代码
#include <QApplication>
#include <QStyle>
#include <QToolButton>
#include <QTabWidget>
#include <QTabBar>
 
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();
}
 
复制代码

界面效果:

 


相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页