Solved QFormLayout , how to remove rows having widgets
-
Hi,
I am using QFormLayout, i am dynamically adding QLabel and QComboBox, to the rows using addrow(); if i try to add , previous elements are also present, how to remove rows of previously added.
for (int i = 1; i <= nrow; i++) { for (int j = 1; j <= ncol; j++) { QLabel *gridLabel = new QLabel ; gridLabel->setText(QString::number(i)) ; QComboBox *cb = new QComboBox; cb->addItems(camidList) ; m_pQFormLayoutGrid->addRow(gridLabel, cb); } }
How to remove previous rows from m_pQFormLayoutGrid, when i try to add new rows?.
Thanks,
-
@Pradeep-Kumar
QFormLayout::removeRow may be a choice -
Hi,
I didnt find removeRow() for QFormLayout?.
-
declare QObjectList in header file.
//In Header FileQObjectList objectList;
//In Function
if(objectList.length()!=0){
for(int item =0;item<objectList.length();item++){
delete objectList(item);
}
objectList.clear();
}
for (int i = 1; i <= nrow; i++)
{
for (int j = 1; j <= ncol; j++)
{
QLabel *gridLabel = new QLabel ;
gridLabel->setText(QString::number(i)) ;QComboBox *cb = new QComboBox; cb->addItems(camidList) ; m_pQFormLayoutGrid->addRow(gridLabel, cb);
objectList.append(gridLabel);
objectList.append(cb);
}
}Try this.Above code may help you.
-
@Pradeep-Kumar
sorry,QFormLayout::removeRow
is introduced in Qt 5.8
@Venkatesh-V's method is a good choiceby the way, @Venkatesh-V I think you don't need the
if
statement before thedelete
for
, since the condition infor
have test it -
Hi,
@Venkatesh-V
Thank you it worked.
I was trying to remove Qformlayout items by taking itemAt().Thanks,
-
@Flotisable
for the first time of method execution ObjectList size will be 0, on that time delete obectList item will crash the program because of index out of range. so i am setting flag there. -
Hi,
if(objectList.length()!=0) { for(int item =0;item<objectList.length();item++) { delete objectList.at(item); } objectList.clear(); }
used the above line of code before adding to the QFormLayout.
It worked,
May be in 5.8 we can use QFormLayout::removeRow() i guess,
I will try in some while in 5.8 for QFormLayout.Thanks @Venkatesh-V
@Flotisable ,Thanks,
-
@Pradeep-Kumar
If it works fine, mark it as solved.