Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Hiding the control in a layout and filling it with the other control



  • I have to custom widgets which are displayed side by side in a QHBoxLayout as shown in the picture.

    0b36ea40-113c-4a78-aaf6-af572952b8b2-image.png

    In the Widget2 there is a signal attached to a slot which constantly monitors for a variable. if the variable is null then widget2 should not be displayed and widget1 should stretch to the entire area of the layout. as shown in the picture below.

    725c6b27-669c-4215-8ff4-ff675abb9962-image.png

    What I have written for the state when the two widgets are displayed

    widget1 = new Widget1(this);
    widget2 = new Widget2(this);
    QHboxLayout* hLayout = new QHboxLayout();
    hLayout->addwidget( widget1,5);
    hLayout->addwidget(widget2,95);

    How I can hide this and achieve the state 2 based on the subscribed variable change output?



  • @thomasjohnaj

    widget2->setVisible(false);
    or
    widget2->hide();

    Edit:
    You mixed the names in your image and in your description text. "Widget1 should stretch", but image label says "widget2" :)
    But doesnt matter... it's the same for every widget :)


Log in to reply