CodePudding user response:
Show/hide don't you?CodePudding user response:
I put you said this effect achieved, close test and correct... In the UI white_label and remember_label you said in the same layout, switch display code is as follows: the Widget: : widgets (QWidget * parent) : QWidget (parent), UI (new UI: : Widget) {UI - & gt; SetupUi (this); flag=false; The UI - & gt; HorizontalLayout - & gt; RemoveWidget (UI - & gt; Label);//hide the label init. UI - & gt; The label - & gt; SetVisible (false); }//here I use a slot to realize switching display void Widget: : on_pushButton_clicked () {if (! Flag) {UI - & gt; HorizontalLayout - & gt; RemoveWidget (UI - & gt; ProgressBar); The UI - & gt; HorizontalLayout - & gt; AddWidget (UI - & gt; Label); The UI - & gt; ProgressBar - & gt; SetVisible (false); The UI - & gt; The label - & gt; SetVisible (true); } else {UI - & gt; HorizontalLayout - & gt; RemoveWidget (UI - & gt; Label); The UI - & gt; HorizontalLayout - & gt; AddWidget (UI - & gt; ProgressBar); The UI - & gt; ProgressBar - & gt; SetVisible (true); The UI - & gt; The label - & gt; SetVisible (false); } flag=! Flag; }CodePudding user response:
Thank you upstairs, according to your inspiration, I also added the setVisible function, originally because of it, but this is enough trouble, the switch is not enough, also manually changing control reality, don't know QT has its reason to do so? But as a developing KDE software library, ought to admire it, rather than doubt,,, PS, maybe can consider to use QStackedLayoutCodePudding user response:
Qlayout is responsible for managing the qwidget size, location, not to control component is visible or notCodePudding user response:
After removing the widget from the layout, also need to this widget using setParent (null)