Add/Delete Multiple Widgets to QGridLayout Programmatically
-
@Radio1985 The code only adds one row and not multiple, because you don't increment the row number in each "addWidget"-call. In each loop, you have to retrieve the current row count and set it accordingly. Something like this:
int row_count = specGridLayout->rowCount(); specGridLayout->addWidget(specNameLine, row_count , 0, 0, 0, Qt::AlignLeft); specGridLayout->addWidget(specTypeLine, row_count , 1, 0, 5, Qt::AlignLeft); specGridLayout->addWidget(rangeTypeCombo, row_count , 7, 0, 5, Qt::AlignLeft);
Edit: You write that you've tried this already. That should work, though...
@qwasder85
Thanks for the reply. I added the row_count as above. But then I get this error below:
Now I don't see anything when I click the button
-
@qwasder85
Thanks for the reply. I added the row_count as above. But then I get this error below:
Now I don't see anything when I click the button
@Radio1985 said in Add/Delete Multiple Widgets to QGridLayout Programmatically:
But then I get this error below
Show the code...
-
@qwasder85
Thanks for the reply. I added the row_count as above. But then I get this error below:
Now I don't see anything when I click the button
-
@Radio1985
...As @jsulm says, and show the values of the "fromRow" and "toRow" you are passing....I am using the same code above. Added the additional lines below:
int row_count = specGridLayout->rowCount(); specGridLayout->addWidget(specNameLine, row_count, 0, 0, 0, Qt::AlignLeft); specGridLayout->addWidget(specTypeLine, row_count, 1, 0, 5, Qt::AlignLeft); specGridLayout->addWidget(rangeTypeCombo, row_count, 7, 0, 5, Qt::AlignLeft);
-
I am using the same code above. Added the additional lines below:
int row_count = specGridLayout->rowCount(); specGridLayout->addWidget(specNameLine, row_count, 0, 0, 0, Qt::AlignLeft); specGridLayout->addWidget(specTypeLine, row_count, 1, 0, 5, Qt::AlignLeft); specGridLayout->addWidget(rangeTypeCombo, row_count, 7, 0, 5, Qt::AlignLeft);
@Radio1985
I would start by changing all your row and columns spans which are0
--- which does not make sense --- to 1?On a separate matter, are you aware that with the column starts+spans you specify column #6 will be empty?
-
@Radio1985
I would start by changing all your row and columns spans which are0
--- which does not make sense --- to 1?On a separate matter, are you aware that with the column starts+spans you specify column #6 will be empty?
@JonB
Thanks, yes it works when I change the spans to 1. I get the following. The issue was the row_number starts with 1, even if I don't have added any rows.Now I have the other issue on aligning them according to the the label positions I have added.
I am not that clear on how the span and positions working.I modify the addWidget as below:
specGridLayout->addWidget(specNameLine, row_count, 0, 1, 1, Qt::AlignLeft); specGridLayout->addWidget(specTypeLine, row_count, 1, 2, 1, Qt::AlignLeft); specGridLayout->addWidget(rangeTypeCombo, row_count, 3, 1, 1, Qt::AlignLeft);
Then I get the following results.
I want to align them according to the label on top.
-
@JonB
Thanks, yes it works when I change the spans to 1. I get the following. The issue was the row_number starts with 1, even if I don't have added any rows.Now I have the other issue on aligning them according to the the label positions I have added.
I am not that clear on how the span and positions working.I modify the addWidget as below:
specGridLayout->addWidget(specNameLine, row_count, 0, 1, 1, Qt::AlignLeft); specGridLayout->addWidget(specTypeLine, row_count, 1, 2, 1, Qt::AlignLeft); specGridLayout->addWidget(rangeTypeCombo, row_count, 3, 1, 1, Qt::AlignLeft);
Then I get the following results.
I want to align them according to the label on top.
@Radio1985 said in Add/Delete Multiple Widgets to QGridLayout Programmatically:
I want to align them according to the label on top
You added spacers in the first row, but you do not do that for the other rows. That's why they do not align.
-
@Radio1985 said in Add/Delete Multiple Widgets to QGridLayout Programmatically:
I want to align them according to the label on top
You added spacers in the first row, but you do not do that for the other rows. That's why they do not align.
-
@Radio1985
I don't understand what exactly is wrong/you want to do from your pictures. Perhaps @jsulm does. But, yes, anything can be added programmatically. In fact if you design to produce a.ui
file that gets processed into aui_....h
file with C++ code to implement everything designed. So "everything is programmatic". You can even examine theui_...h
file if you want to see what code is generated, for you to maybe copy and use elsewhere. -
@Radio1985 said in Add/Delete Multiple Widgets to QGridLayout Programmatically:
Is there is away I can add them programmatically?
Why do you need them? Why don't you simply left align the elements in first row?
-
@Radio1985 said in Add/Delete Multiple Widgets to QGridLayout Programmatically:
Is there is away I can add them programmatically?
Why do you need them? Why don't you simply left align the elements in first row?