PDA

View Full Version : How to arrange the buttons in a layout after deletion of one or two from the middle



Soumya Somasekhar Ram
24th September 2013, 05:23
I want to maintain a gridlayout.While adding buttons,it should be in the row by column manner and when we delete any item, the remaining items should be rearranged to maintain the currect layout.
can u suggest any method to neatly arrange the buttons.
Thanks in advance.

ChrisW67
24th September 2013, 05:59
What do you mean by "currect layout" or "neatly arrange"? Items in a grid layout stay in the cell you put them in. If you remove widgets from cells the row/column height/width is driven by the items remaining in that row/column.

Soumya Somasekhar Ram
25th September 2013, 07:22
Thank you for your response.By correctly or neatly I mean that while deleting any button from the middle,after deletion there should not be a gap between the remaining buttons.
If it is a 4*4 grid layout,and it contains 16 buttons. when I delete a button from the position (1,2) , then the button from the position(1,3) shold be moved to the position(1,2) and button(1,4) to (1,3) and so on. The last position should be empty, and i can add new buttons to that position.
All your suggestions are appreciable.
Thanks in advance.

aamer4yu
25th September 2013, 09:56
That exactly isnt a grid layout what you want. In grid layout, you specify rows and columns for the cells.

What you want is a flowlayout with the items having a particular size. Search for flowlayout in Qt.

nish
25th September 2013, 10:43
keep your buttons in a QList<QPushButton*>, whenever a button is deleted, remove it from the list. Now iterate over the list and add every button in the grid layout again.

Soumya Somasekhar Ram
25th September 2013, 11:52
how can I get the current row and column of the grid layout????

nish
26th September 2013, 06:53
do simple math. check the index of deleted button in list, 2nd is in cell (0,2)