首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > QT开发 >

QTabWidget的第二个tab如何设置sheetStyle?

2013-04-02 
QTabWidget的第二个tab怎么设置sheetStyle???如上图所示,第一个tab可以设置图片,第三个tab也可以设置,但第

QTabWidget的第二个tab怎么设置sheetStyle???
QTabWidget的第二个tab如何设置sheetStyle?

如上图所示,第一个tab可以设置图片,第三个tab也可以设置,但第二tab个不知道怎么设置。下面是设置sheetStyle的语句,设置第一个tab用了first,第三个tab用last,但第二个用second不行啊。
    m_pTabWidget->setStyleSheet("\
                QTabBar::tab\
                {\
                    width:50px;\
                    height:25px;\
                }\
                QTabBar::tab:first:selected\
                {\
                            background-image:url(:/image/Operater_MouseDown.png);\
                }\
                QTabBar::tab:first:!selected\
                {\
                            background-image:url(:/image/Operater_Normal.png);\
                }\
                QTabBar::tab:first:hover\
                {\
                            background-image:url(:/image/Operater_Hover.png);\
                }\
                QTabBar::tab:last:selected\
                {\
                            background-image:url(:/image/Extend_MouseDown.png);\
                }\
                QTabBar::tab:last:!selected\
                {\
                            background-image:url(:/image/Extend_Normal.png);\
                }\
                QTabBar::tab:last:hover\
                {\
                            background-image:url(:/image/Extend_Hover.png);\


                }"\
                );
[解决办法]
这个问题我也纠结过 实在是找不到设置第二个tab的方法

后来是自己写个槽函数去替代解决

setStyleSheet("QTabBar::tab {\
        height: 45px;\
        width: 60px;\
    }\
    QTabBar::tab:selected{\
      background-color: rgb(51,51,51);\
    }\
    QTabWidget::pane {\
       border: 1px solid #C2C7CB;\
       background-color: rgb(51, 51, 51);\
      }\
    }");

connect(this,SIGNAL(currentChanged(int)),this,SLOT(tabSelectChanged(int)));

void AudioTabWidget::tabSelectChanged(int index)
{
    switch(index){
        case TAB_GRP: /*选中群组tab*/
            this->setTabIcon(TAB_GRP,QIcon(":/res/icon/tab_grp_selected.png"));
            this->setTabIcon(TAB_USER,QIcon(":/res/icon/tab_user_unselected.png"));
            this->setTabIcon(TAB_CAMERA,QIcon(":/res/icon/tab_camera_unselected.png"));
            this->setTabIcon(TAB_CLT,QIcon(":/res/icon/tab_collect_unselected.png"));
            break;
        case TAB_USER: /* 选中用户tab */
            this->setTabIcon(TAB_GRP,QIcon(":/res/icon/tab_grp_unselected.png"));
            this->setTabIcon(TAB_USER,QIcon(":/res/icon/tab_user_selected.png"));
            this->setTabIcon(TAB_CAMERA,QIcon(":/res/icon/tab_camera_unselected.png"));
            this->setTabIcon(TAB_CLT,QIcon(":/res/icon/tab_collect_unselected.png"));
            break;
        case TAB_CAMERA: /* 选中摄像头tab */
            this->setTabIcon(TAB_GRP,QIcon(":/res/icon/tab_grp_unselected.png"));
            this->setTabIcon(TAB_USER,QIcon(":/res/icon/tab_user_unselected.png"));
            this->setTabIcon(TAB_CAMERA,QIcon(":/res/icon/tab_camera_selected.png"));
            this->setTabIcon(TAB_CLT,QIcon(":/res/icon/tab_collect_unselected.png"));
            break;
        case TAB_CLT: /* 选中收藏tab */
            this->setTabIcon(TAB_GRP,QIcon(":/res/icon/tab_grp_unselected.png"));
            this->setTabIcon(TAB_USER,QIcon(":/res/icon/tab_user_unselected.png"));


            this->setTabIcon(TAB_CAMERA,QIcon(":/res/icon/tab_camera_unselected.png"));
            this->setTabIcon(TAB_CLT,QIcon(":/res/icon/tab_collect_selected.png"));
            break;
        default:
            break;
        }
}

方法比较土,不知道有没高人有更好的办法...

热点排行