moijhd
26th March 2013, 09:23
Hi,
I have a QGridLayout in a Widget. This layout is divided into four parts by placing four widgets in it.
I want to be able to remove the four internal widgets and the just put one of them in the layout (which will occupy the whole space).
I am currently using the following code to remove the elements in the layout (without destroying them because I want to reuse them later) :
QLayoutItem *child;
while((child = this->gridLayout->takeAt(0)) != 0);
And then I add the new widget in the layout.
My problem is that the old items are still visible and the new one is just displayed on them...I don't understand why. The old widgets are displayed but they don't follow the layout rules (like they are not in it, they are just still "present" in the display).
Any leads ?
Thanks
PS 1 : The widget are actually QwtPlot and here is what I see on the scale for example : 8858
PS 2 : Also, the same thing is observed when I delete the layout and create a new one. Some how, the old one is still visible.
PS 3 : The problem can be seen with this code
QWidget *w = new QWidget();
w->setLayout(new QGridLayout());
static_cast<QGridLayout*>(w->layout())->addWidget(new QToolButton(), 0, 0);
static_cast<QGridLayout*>(w->layout())->addWidget(new QToolButton(), 0, 1);
static_cast<QGridLayout*>(w->layout())->addWidget(new QToolButton(), 1, 0);
static_cast<QGridLayout*>(w->layout())->addWidget(new QToolButton(), 1, 1);
delete w->layout();
w->setLayout(new QGridLayout());
static_cast<QGridLayout*>(w->layout())->addWidget(new QLabel(QString("hey")), 0, 0);
w->show();
Running that displays the label in the new label (in place) but there is still one old button in the background (it is unclickage, it is just drawn)...
I have a QGridLayout in a Widget. This layout is divided into four parts by placing four widgets in it.
I want to be able to remove the four internal widgets and the just put one of them in the layout (which will occupy the whole space).
I am currently using the following code to remove the elements in the layout (without destroying them because I want to reuse them later) :
QLayoutItem *child;
while((child = this->gridLayout->takeAt(0)) != 0);
And then I add the new widget in the layout.
My problem is that the old items are still visible and the new one is just displayed on them...I don't understand why. The old widgets are displayed but they don't follow the layout rules (like they are not in it, they are just still "present" in the display).
Any leads ?
Thanks
PS 1 : The widget are actually QwtPlot and here is what I see on the scale for example : 8858
PS 2 : Also, the same thing is observed when I delete the layout and create a new one. Some how, the old one is still visible.
PS 3 : The problem can be seen with this code
QWidget *w = new QWidget();
w->setLayout(new QGridLayout());
static_cast<QGridLayout*>(w->layout())->addWidget(new QToolButton(), 0, 0);
static_cast<QGridLayout*>(w->layout())->addWidget(new QToolButton(), 0, 1);
static_cast<QGridLayout*>(w->layout())->addWidget(new QToolButton(), 1, 0);
static_cast<QGridLayout*>(w->layout())->addWidget(new QToolButton(), 1, 1);
delete w->layout();
w->setLayout(new QGridLayout());
static_cast<QGridLayout*>(w->layout())->addWidget(new QLabel(QString("hey")), 0, 0);
w->show();
Running that displays the label in the new label (in place) but there is still one old button in the background (it is unclickage, it is just drawn)...