Unsolved How to delete a row of a QGridLayout
-
Try to remove the widget from your layout (instead of hiding it).
-
-
@maxime0601 said in How to delete a row of a QGridLayout:
It continues to crash
then please use the debugger to see what exactly happens and where...
-
-
@jsulm I have a signal of segmentation fault. It confirms that I try to use an outside element of my grid
-
@maxime0601 said in How to delete a row of a QGridLayout:
I try to use an outside element of my grid
Well, then fix that. And I know that it is crashing and my suggestion to use debugger is still valid: you will see where exactly it is crashing and what the values of variables at that time.
Did you read what @JonB wrote? -
-
@jonb I'm sorry if I don't understand what you mean but when I tried itemAtPosition(row,0) it crashes.
Which is why I said your program crashes all the time! You are not understanding that rows are numbered starting from 0 and going to
rowCount() - 1
, not torowCount()
. That's how most arrays etc. are numbered in C/C++. I don't know how to explain any better, you really need to understand this fundamental, rather than banging stuff in without understanding:Oh I tried with
row - 1
and it seems worksYou really need to understand why that it is, rather than "seems to work".
-
int row = this->rowCount(); int col = this->columnCount(); if (row > 6) { for (int i(0); i < col ; ++i) { this->itemAtPosition(row - 1,i)->widget()->hide(); delete this->takeAt(row - 1); } }
So, when I used this code, the last row disappeared as I want but the disposition of the others elements in the grid changes.
@JonB yes I knew this for vector but I totally forgot it. I'm sorry for that.
-
@maxime0601
I'm sorry but it's more complex than you are expecting. You really need to read https://stackoverflow.com/questions/5395266/removing-widgets-from-qgridlayout. I know it looks a lot more involved than what you are trying, but there you are.... -
@jonb Thanks a lot, I've searched but I don't found similar topic. I think that I can succeed with this.
Thanks a lot everyone for your help