开发者

QtabBar text and icon

开发者 https://www.devze.com 2023-03-09 01:22 出处:网络
hi i would like to place icon and an text below the icon in each tab of an tabbar in QtabBar widget. by default the text and icon ar开发者_如何学JAVAe set next to each other i would like to display on

hi i would like to place icon and an text below the icon in each tab of an tabbar in QtabBar widget. by default the text and icon ar开发者_如何学JAVAe set next to each other i would like to display one below the other . how can we do it .


There seems to be only one way to change icon placement - reimplement QTabBar's paintEvent. Code like this may help:

class MyTabBar : public QTabBar
{
    ...
protected:
    void paintEvent(QPaintEvent *) {
        QStylePainter painter(this);
        for(int i = 0; i < 3; ++i) {
            QStyleOptionTabV2 option;
            initStyleOption(&option, i);
            painter.drawItemPixmap(option.rect, Qt::AlignTop|Qt::AlignHCenter, option.icon);
            painter.drawItemText(option.rect, Qt::AlignBottom|Qt::AlignHCenter, palette(), 1, option.text);
        }
    }
};
0

精彩评论

暂无评论...
验证码 换一张
取 消