From 42d681f9cfc984046a93b9efe19903d46ac68bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Mon, 3 Sep 2012 06:35:39 +0200 Subject: Add widget replace function to QLayout Sometimes it is nice to be able to replace a widget in a layout. Change-Id: I23a6a65e417e94d53bc48639503db1a142bc3f10 Reviewed-by: J-P Nurmi --- src/widgets/kernel/qgridlayout.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/widgets/kernel/qgridlayout.cpp') diff --git a/src/widgets/kernel/qgridlayout.cpp b/src/widgets/kernel/qgridlayout.cpp index 96820e3891..7da2104971 100644 --- a/src/widgets/kernel/qgridlayout.cpp +++ b/src/widgets/kernel/qgridlayout.cpp @@ -85,6 +85,7 @@ public: void setGeometry(const QRect &r) { item_->setGeometry(r); } Qt::Alignment alignment() const { return item_->alignment(); } QLayoutItem *item() { return item_; } + void setItem(QLayoutItem *newitem) { item_ = newitem; } QLayoutItem *takeItem() { QLayoutItem *i = item_; item_ = 0; return i; } int hStretch() { return item_->widget() ? @@ -171,6 +172,18 @@ public: } return 0; } + QLayoutItem* replaceAt(int index, QLayoutItem *newitem) Q_DECL_OVERRIDE + { + if (!newitem) + return 0; + QLayoutItem *item = 0; + QGridBox *b = things.value(index); + if (b) { + item = b->takeItem(); + b->setItem(newitem); + } + return item; + } void getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan) const { if (index < things.count()) { -- cgit v1.2.3