QLayout删除所有布局


Qt 的 QLayout 文档里是这么写的,但其实不完整,参看我最下面的代码。

[pure virtual] QLayoutItem *QLayout::takeAt(int index)
Must be implemented in subclasses to remove the layout item at index from the layout, and return the item. If there is no such item, the function must do nothing and return 0. Items are numbered consecutively from 0. If an item is removed, other items will be renumbered.
The following code fragment shows a safe way to remove all items from a layout:

-------------不完整的方式------------

QLayoutItem *child;
while ((child = layout->takeAt(0)) != 0) {
    ...
    delete child;
}

-----------正确方式--------

    QLayoutItem *child;
    while ((child = layout->takeAt(0)) != 0)
    {
        layout->removeWidget(child->widget());
        child->widget()->setParent(0);
        delete child;
    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM