QtabBar text and icon

南笙酒味 提交于 2019-12-11 03:57:20

问题


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 are set next to each other i would like to display one below the other . how can we do it .


回答1:


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);
        }
    }
};


来源:https://stackoverflow.com/questions/6177125/qtabbar-text-and-icon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!