I have qtablewidget with delegates. If a cell does not receive a value, e.g. the cell is empty and the user tries to open its editor, it crashes? How do I avoid the crash? I would like to be able to disable the cell if there is no value.
Printable View
I have qtablewidget with delegates. If a cell does not receive a value, e.g. the cell is empty and the user tries to open its editor, it crashes? How do I avoid the crash? I would like to be able to disable the cell if there is no value.
you can make value checking in createEditor of your delegate and if value is empty retun 0.
What does the debugger say about the crash? Can you show us the backtrace?
Anyway, you can disable editing a cell by returning proper flags from your model (i.e. don't return ItemIsEditable for the item).
Sorry...my mistake...it does not crash...but the editor opens with the minimum value of the spinbox.
ok...I set item->setFlags(Qt::ItemIsSelectable) to disable the cell if there is no value. It works, But...is it not possible to set item->setFlags(Qt::ItemIsEditable) if a value shows up later on? That does not work?
You can change the flags at any time.
Well...I am doing something wrong?
This is the table constructor...
Code:
. . . pItemTorque->setTextAlignment(Qt::AlignHCenter); setItem(ROW_TORQUE, SECOND_COLUMN, pItemTorque); . . .
...and this is the method that is called to populate the cell...
Code:
{ if(torque.isEmpty()) { torqueItem->setFlags(Qt::ItemIsSelectable); } else { torqueItem->setFlags(Qt::ItemIsEditable); } }
It is ok if the cell is editable if a value is set. If a value is not set the cell is just selectable...and if a value comes along the setFlags(Qt::ItemIsEditable) does not work...in fact the app. goes down. What am i doing wrong?
You probably want to set more than one flag at once...
Code:
item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsEditable);
I am not sure where and how the flags should be set? I think I have tried every combination of setflags for every state the parameter value can be in, but can't get it to work properly?
What do you do, what do you get and what do you expect?