Change tab widget - no tab content / page

  • Hi
    I would like to change the widget of one of my tabs in QTabWidget like in gtkD:
    I mean to put whatever e.g. QPushButton instead of label in tab.

    I know about function:
    void QTabBar setTabButton ( int index, ButtonPosition position, QWidget *widget …),
    but I would like to make my widget was the only one in the my tab and to be centered in it - not aligned to the left or right

    Can I do it in C++/Qt?

    Sorry for my English

  • If you use the layout system Qt provides, you will be able to center your widget.

    Also, you can add and remove widgets from layouts dynamically through code, so that's how your going to want to replace your QLabel with the QPushButton.

    If your in the designer, you can right click on your tab pane, and select the desired layout / add spacers to center your widget / etc.

    Have a look at:

  • I do not know if you understand my question.
    I know about layouts etc.
    For eg. application with QTabWidget ( fan-ascii-art ):
    In gtkD I can change label "Tab 1" with widget which I choose.
    I do not want to change "CONTENT" - I know how do that.
    In gtkD that function is:
    void setTabLabel (Widget child, Widget tabLabel);
    The child is "CONTENT" and tabLabel is "Tab 1".
    Can I do that in C++/Qt?

    Thanks for your time.

  • You can use:
    @int QTabWidget::addTab ( QWidget * page, const QIcon & icon, const QString & label )@
    and add any widget as you wish.
    In other way, you need layouts.

  • euh, use the tabwidget->setTabText()

  • Sorry, but you do not understand.
    I am not surprised because I search for that function in QTabBar and QTabWidget classes many times.
    I know how to change "CONTENT" ( see image ) / tab page.
    "euh, use the tabwidget->setTabText()" - no, it's only change text in label.
    I would like to change that tab label with widget which I choose.
    In gtkD I can change both: tab label text, tab label and tab page.
    In Qt I found only how to change tab label text and tab page.
    Please look at:
    On "Tab 2 - AFTER" is button with this text.
    This is only example.
    Can I do that in C++/Qt?
    Thanks for help and your time.

  • So do you just want the last tab to be a button that does some function?

    If that is the case, why not just implement a your own TabWidget class that inherits from QTabWidget and add a clicked() signal. Then you could connect it to a function that would check the tab index, and do what you want from there.

    You could have it create a new tab, open a file, make a little robot dance, or take over the world (if you have the take over the world function working).

  • Not only last tab.
    It is only example BEFORE-AFTER.

    clicked() signal ... - no, I want button in tab ( button only for example - may be any QWidget )
    I used signals and slots in past - I some know about it.

    I searched for similar function like in gtkD.
    I do not found it, so implement own TabWidget is generally the only idea I have.

    I would have to the button in tab by default or can change widget by function like in gtkD, but I do not have idea how to implement this in my class.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.