Qlayout Dynamic Layout (how to clear the layout)

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.