Remove all items from layout without destroying the items.
-
I am aware how tab widget works.
I took a screenshot so you see how my app will look:

the tab on the left will also update its content and the part on the right will be a list of entries.
Also I plan on adding more information to the left-hand tab later on -
said in Remove all items from layout without destroying the items.:
how do I Unattach items from layout without removing them?
There is a TakeAt function that gives ownership back
http://doc.qt.io/qt-4.8/qlayout.html#takeAt -
Okay I am getting somewhere with this, but now the container is not being repainted and everything stays on the screen (overlaps), this is my redraw function:
void clearLayout(QLayout * layout) { if (layout) { while(layout->takeAt(0) != 0){} } } void MainWindow::reload() { for(auto && i : this->tabs) { this->ui->tabsList->addItem(i); //redraws the panel on the left } clearLayout(this->ui->verticalLayout_2); //clears the layout if(selectedTab >= 0) { this->ui->verticalLayout_2->setAlignment(Qt::AlignTop); //if any tab is selected draws the coresponding panel this->ui->verticalLayout_2->addLayout(this->tabs.at(selectedTab)->tabContent); } else { this->ui->actionUsu_aktywny_arkusz->setEnabled(false); //if no tab is selected disable the remove tab button in the menu } this->ui->verticalLayout_2->update();//update the redrawn layout repaint();//repaint main window update();//update main window }
here you can see as it overlaps
any ideas?edit
i have noticed i can do this:QLayoutItem * child; while((child = layout->takeAt(0)) != 0){ child->widget()->hide(); }but then it crashes when i switch to another tab or click the same one again, segfault is fired at the "hide" line
-
Okay I am getting somewhere with this, but now the container is not being repainted and everything stays on the screen (overlaps), this is my redraw function:
void clearLayout(QLayout * layout) { if (layout) { while(layout->takeAt(0) != 0){} } } void MainWindow::reload() { for(auto && i : this->tabs) { this->ui->tabsList->addItem(i); //redraws the panel on the left } clearLayout(this->ui->verticalLayout_2); //clears the layout if(selectedTab >= 0) { this->ui->verticalLayout_2->setAlignment(Qt::AlignTop); //if any tab is selected draws the coresponding panel this->ui->verticalLayout_2->addLayout(this->tabs.at(selectedTab)->tabContent); } else { this->ui->actionUsu_aktywny_arkusz->setEnabled(false); //if no tab is selected disable the remove tab button in the menu } this->ui->verticalLayout_2->update();//update the redrawn layout repaint();//repaint main window update();//update main window }
here you can see as it overlaps
any ideas?edit
i have noticed i can do this:QLayoutItem * child; while((child = layout->takeAt(0)) != 0){ child->widget()->hide(); }but then it crashes when i switch to another tab or click the same one again, segfault is fired at the "hide" line
@Szustarol
When u take items back. they are not removed from screen. Just not owned
by layout anymore. -
@Szustarol
Delete the QLayoutItem and widget when you take them out.
Then insert the new widgets. -
If i do this and then want to go back to the tab I've been deleting from the app crashes.
So this'd be error in my code?
because i guess when i delete those items I cant reshow them anymore, because they are deleted right?@Szustarol
if u delete them , then yes they are gone.
but if u want to reuse them u can keep in list and reload etc.If you crash, make sure nothing u delete is selected or active.
-
Okay sorry for keeping the thread dead for some time.
I have been trying your soultion, but copy constructor cannot be used so i cannot make a list of temporary objects i'd like to display.
Let's say you have a vector of QWidgets and you want to create another vector, with exactly the same QWidgets, how would you do it, because i have seriously no idea -
Okay sorry for keeping the thread dead for some time.
I have been trying your soultion, but copy constructor cannot be used so i cannot make a list of temporary objects i'd like to display.
Let's say you have a vector of QWidgets and you want to create another vector, with exactly the same QWidgets, how would you do it, because i have seriously no idea@Szustarol said in Remove all items from layout without destroying the items.:
make a list of temporary objects i'd like to display.
std::vector<QWidget *> mylist will be able to hold it those you take out.
(or Qlist)- you want to create another vector, with exactly the same QWidgets,
That is not really possible.
- you want to create another vector, with exactly the same QWidgets,