Re-layout-ing in a subclass



  • Hi my friends.
    I have a question. I have a class, named Base which is a QDialog, and this have a very heavy population of widgets and established connection. It is possible to create a subclass of Base, called "Derived", which use all this created widgets of Base, and only make global changes of structure of layout of Base, and also add some other widgets ?
    In other words, it is possible, to use Base created widgets, and simply re-layout it ? I read about that we cannot set 2 times "setLayout" if we not delete previously layout, So if i delete a layout, it will also delete his containing widgets ?
    Greatings and thanks for any help.
    Daniel


  • Qt Champions 2016

    Hi
    Yes you can re-layout but layout owns the widget so you must take them out before you remove layout
    something like.

    void RemoveLayout (QWidget* widget)
    {
        QLayout* layout = widget->layout ();
        if (layout != 0)
        {
        QLayoutItem *item;
        while ((item = layout->takeAt(0)) != 0)
            layout->removeItem (item);
        // keep or add to other layout
        delete layout;
        }
    }
    


  • Thanks.
    It is exactly what i need to know.
    Daniel


Log in to reply
 

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