zoukankan      html  css  js  c++  java
  • 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;
        }
  • 相关阅读:
    随机数
    质数
    猜数
    失败
    判断质数
    2019.7.21记录
    9*9乘法表
    小人
    奔跑的字母

  • 原文地址:https://www.cnblogs.com/qtgameprograming/p/10111987.html
Copyright © 2011-2022 走看看