Important: Please read the Qt Code of Conduct -

Newbie Qtabwidget Question

  • Hi Guys,

    I'm a newb, and wondering how to deal with QtabWidget. I've got two seporate Qdialog subclasses which i'd like to try and add onto two different tabs. Both subclasses have been created using the designer.

    I'm a total loss as to how to do this or where to look for info about doing it.

    could anyone please advise or point me in the direction of a tutorial that does something similar.

    Thanks in advance.

  • Normally, you would just create the tabwidget, create the widgets you want to put in it as tabs, and add them to the tabwidget using the addTab() function.

    But, you say you have two QDialog subclasses. Having QDialog subclasses in a tabwidget might be possible, but seems a bit strange to me. Why are they QDialog subclasses and mot just QWidget subclasses?

  • A QDialog (and subclasses thereof) are meant as top level windows. That means that there is no (easy) way to add those to separate pages in a tab widget.

    You should have based the two contents pages off off QWidget, not QDialog, and use those instead. The QWidget based pages can then be added to the dialog using widget promotion. Alternatively, you can just copy/paste the contents of your separate dialogs to the contents of the QTabsWidget pages you want to context on. Don't forget to apply a layout on each page.

  • If you want to look at some code that uses QTabWidget, have a look at the "tabdialog": example.

  • Thanks for this - I think i'll use QWidget instead of QDialog as a parent class. However, i have managed to get it working but the size is just a little weird. It cuts off 3 quarters of my dialog window so i have to manually resize this each time the app is run.

    I'm hoping that using QWidget instead of QDialog will sort this..

Log in to reply