qformlayout cleanup/repaint after takerow()
-
wrote on 8 Apr 2025, 18:38 last edited by
Using Qt 5.14.0, I have created a formlayout to edit a list of parameters. Depending on the state of a checkbox, several rows are inserted or taken out. All works as I want, except that the text for the taken rows is not cleared. This results in the images below:
The code in question is this:
void EC_tab::insertPID(int state) { if (state != 0) { formLayout->insertRow(12, new QLabel(tr("Proportional Constant:")),PID_Kp); formLayout->insertRow(13, new QLabel(tr("Integral Constant")),PID_Ki); formLayout->insertRow(14, new QLabel(tr("Derivative Constant:")),PID_Kd); formLayout->insertRow(15, new QLabel(tr("Anti-Windup Constant:")),PID_Ks); } else { formLayout->takeRow(PID_Kp); formLayout->takeRow(PID_Ki); formLayout->takeRow(PID_Kd); formLayout->takeRow(PID_Ks); } setLayout(formLayout); //I've tried adding this but it doesn't help }
Is there something else I need to do to repaint the form after taking rows?
file:///home/mark/Pictures/Screenshot%20from%202025-04-08%2014-20-28.png
file:///home/mark/Pictures/Screenshot%20from%202025-04-08%2014-21-11.png
file:///home/mark/Pictures/Screenshot%20from%202025-04-08%2014-21-58.png
-
wrote on 8 Apr 2025, 19:00 last edited by
Followup: using removerow() and recreating the widgets when they are needed seems to work. It isn't obvious to me what takerow() would be useful for.
-
Hi,
AFAIR, there have been some patches related to takeRow (but it's been some time).
It's technically exactly the method you want to use however 5.14 is pretty outdated. If possible you should try the latest 5.15 if not Qt 6. -
-
Hi,
AFAIR, there have been some patches related to takeRow (but it's been some time).
It's technically exactly the method you want to use however 5.14 is pretty outdated. If possible you should try the latest 5.15 if not Qt 6.wrote on 8 Apr 2025, 19:37 last edited by JonB 4 Aug 2025, 19:37@SGaist
I thoughtremoveRow()
, in this and other cases, was just more or lessdelete takeRow()
(here astruct
, but delete two members), so quite why it is right whentakeRow()
is not I'm not sure. Maybe it does some extra invalidating. -
Oh ! My bad !
I meant that takeRow would allow the OP to not have to recreate the row content every time.
5/5