⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Add widgets in distinct tabs

  • i have some widgets and a QTabWidget with 3tabs.
    how can i add a specific widget to a specific tab (not all the tabs)?

  • Lifetime Qt Champion


    Do you mean add a new widget to the widget in a given tab ?

  • no no, i already have some widgets ( e.g. widget1, widget2, widget3) and some tabs (e.g. tab1,tab2,tab3) .
    i want widget1 to add to tab1,
    widget2 to tab2,
    widget3 to tabs3.

    what i could did was add widget1 to tab1,tab2,tab3.

    how can i add widget1 to only tab1?

  • if you post some code, maybe somebody will be able to look through and give you a hint.

  • You can do it a couple of ways.
    If you have already created widgets that you want to display as a their own tab, then
    QTabWidget *tab_widget;
    QWidget *tab_one;
    QWidget tab_two;
    tab_widget = new QTabWidget;
    tab_one = new QWidget();
    tab_two = new QWidget();

    do stuff to tab_one and tab_two
    If you already have tabs (tab1, tab2, ..., tabn) you can use those as parents for your widgets
    QLabel hi_label("hi", tab1);

    Hopefully this helps

Log in to reply