PDA

View Full Version : Is there a way to group many widgets into one object?



bryanC
14th January 2016, 06:01
I want to group a bunch of widgets, text fields, buttons, labels, etc., into one type of object that can be created and destroyed dynamically while the application is running; is the possible? If so, any quick words on where to get started? Thanks.

yeye_olive
14th January 2016, 09:53
Sure, just define a new widget class (derived from QWidget) and, in its constructor, populate it with all those child widgets and a layout manager. Then you can create as many instances of this compound widget as you want.

To get started, see, for instance, the Calculator example (http://doc.qt.io/qt-5/qtwidgets-widgets-calculator-example.html) in Qt; it defines a Calculator widget with several children. Or you could just create your widget in Design mode in Qt Creator and have it generate all the boilerplate code.