Russian Qt Forum

Qt => Вопросы новичков => Тема начата: Григорий от Апрель 18, 2012, 14:43



Название: Очистка чилдренов...
Отправлено: Григорий от Апрель 18, 2012, 14:43
  Уважаемые форумчане , подскажите как можно вычистить все виджеты входящие в QVBoxLayout...?


Название: Re: Очистка чилдренов...
Отправлено: mutineer от Апрель 18, 2012, 14:48
Вычистить? Тряпкой протереть, чтоли?


Название: Re: Очистка чилдренов...
Отправлено: Григорий от Апрель 18, 2012, 14:51
Вычистить? Тряпкой протереть, чтоли?

уточняю , вычистить в данном случае удалить из памяти с поверхности QLayout


Название: Re: Очистка чилдренов...
Отправлено: Alex Custov от Апрель 18, 2012, 14:52
QLayoutItem * QLayout::takeAt ( int index ) [pure virtual]

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:

Код
C++ (Qt)
QLayoutItem *child;
 
while ((child = layout->takeAt(0)) != 0) {
    ...
    delete child;
}

Удалять ещё и child->widget()


Название: Re: Очистка чилдренов...
Отправлено: mutineer от Апрель 18, 2012, 14:52
например перебрать их при помощи QLayoutItem * QLayout::itemAt ( int index ) и вызвать у них deleteLater()


Название: Re: Очистка чилдренов...
Отправлено: Григорий от Апрель 18, 2012, 15:11
QLayoutItem * QLayout::takeAt ( int index ) [pure virtual]

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:

Код
C++ (Qt)
QLayoutItem *child;
 
while ((child = layout->takeAt(0)) != 0) {
    ...
    delete child;
}

Удалять ещё и child->widget()

Спасибо )) Вопрос закрыт