c++qtuser-interfaceqt5.4

Reset / Clear every item within TabWidget Page


Is it possible to reset / clear every QTabWidgets Pages Items?

I have created the UI using the Designer.

I would hate to statically code a clear mask function since we all now UIs can get quite complex and it would take quite the maintenance work for every item that gets added later on.

If this is not possible I would also be okay with looping over each child item and invoking the clear( ) function if someone could give me a hint as to how I can get the pointer / address of them.


Solution

  • All pages of a QTabWidget are of the type QWidget which is a QObject. The latter has the function

    const QObjectList & QObject::children() const
    

    so you can get all children, iterate over them and invoking the clear(). You should probably check isWidgetType() to make sure you only have widgets and probably also design this function recursively if you plan on having widgets with children of their own (i.e QGroupBox).