Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Setting multiple size to qtabbar



  • hi
    i have a qtabwidget that has a qtabbar
    i want to set different sizes to any tabs
    how can i do that?



  • Have not tried it, but I would assume overriding the QTabBar::tabSizeHint() function would do the trick.



  • can you give me some more information
    for example a bit code
    tnx



  • Sure. You have to create your own subclass of QTabBar, where you override tabSizeHint, something like this:
    @
    class TabBar : public QTabBar
    {
    Q_OBJECT
    public:
    explicit TabBar(QWidget *parent = 0) :
    QTabBar(parent)
    {
    }

    protected:
    QSize tabSizeHint(int index) const
    {
    QSize hint = QTabBar::tabSizeHint(index);

        if (index == 0)
            return QSize(100, hint.height());
        else
            return hint;
    }
    

    };
    @

    To make your tab widget use it, I think you have to subclass QTabWidget as well, something like this:
    @
    class TabWidget : public QTabWidget
    {
    Q_OBJECT
    public:
    explicit TabWidget(QWidget *parent = 0) :
    QTabWidget(parent)
    {
    setTabBar(new TabBar);
    }
    };
    @

    This will make the first tab of a TabWidget have width 100.



  • thanks alot.
    it works so good for me


Log in to reply