The example is the dynamic layout in qtdemo.CodeI will not go into details. Here I will mainly talk about how to clear the layout and the problems encountered and their solutions.
Core code:
Void dialog: rotatewidgets ()
{
Q_assert (rotablewidgets. Count () % 2 = 0 );
Foreach (qwidget * widget, rotablewidgets)
Rotablelayout-> removewidget (widget );
Rotablewidgets. enqueue (rotablewidgets. dequeue ());
Const int n = rotablewidgets. Count ();
For (INT I = 0; I <n/2; ++ I ){
Rotablelayout-> addwidget (rotablewidgets [n-I-1], 0, I );
Rotablelayout-> addwidget (rotablewidgets [I], 1, I );
}
}
It is easy to delete and add widgets to layout by saving the widget list in the queue. However, many people encounter this problem and the widgets in the layout do not disappear after they are deleted, what's going on?
The API documentation provides a safe way to delete controls in layout:
Qlayoutitem * child;
While (child = Layout-> takeat (0 ))! = 0 ){
...
Delete child;
}
Deleting is executed, but the widget still does not disappear...
Finally find the way, http://www.qtcn.org/bbs/simple? T15751.html
| Xtowx |
|
| After I use Delete,ProgramI always reported an error. Later I found the widget. setparent (none) on the Internet, and then layout. removewidget (widget. Haha |
|
The original author may be negligent. None should be null, that is, widget-> setparent (null); compile and run, OK! Very happy!