PDA

View Full Version : Disable an editable cell



SailinShoes
1st September 2008, 16:24
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.

spirit
1st September 2008, 16:31
you can make value checking in createEditor of your delegate and if value is empty retun 0.

wysota
1st September 2008, 16:32
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).

SailinShoes
1st September 2008, 20:21
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?

wysota
1st September 2008, 21:03
You can change the flags at any time.

SailinShoes
1st September 2008, 21:53
Well...I am doing something wrong?

This is the table constructor...


.
.
.
pItemTorque = new QTableWidgetItem;
pItemTorque->setTextAlignment(Qt::AlignHCenter);
setItem(ROW_TORQUE, SECOND_COLUMN, pItemTorque);
.
.
.


...and this is the method that is called to populate the cell...


void PSetConfigurationTable::setTorque(QString torque)
{

QTableWidgetItem *torqueItem = item( 0, 1 );

if(torque.isEmpty())
{

torqueItem->setFlags(Qt::ItemIsSelectable);

}
else
{

torqueItem->setFlags(Qt::ItemIsEditable);

}

torqueItem->setData(Qt::EditRole, QVariant(torque));

}


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?

wysota
1st September 2008, 22:20
You probably want to set more than one flag at once...

item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt ::ItemIsEditable);

SailinShoes
2nd September 2008, 19:38
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?

wysota
2nd September 2008, 22:22
What do you do, what do you get and what do you expect?