Looks like you are using the flags the opposite way, check this out
Qt::ItemFlags flags;
tableWidget ->setRowCount(1);
tableWidget ->setColumnCount(1);
tableWidget ->setItem(0, 0, item);
// set the item editable
item = tableWidget->item(0, 0);
flags = item->flags();
flags |= Qt::ItemIsSelectable | Qt::ItemIsEditable; // set the flag
item->setFlags(flags);
// set the item non-editable (view only), but still selectable
item = tableWidget->item(0, 0);
flags = item->flags();
flags |= Qt::ItemIsSelectable;
flags &= ~Qt::ItemIsEditable; // reset/clear the flag
item->setFlags(flags);
// set the item non-editable (view only), and non-selectable
item = tableWidget->item(0, 0);
flags = item->flags();
flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag
item->setFlags(flags);
QTableWidget *tableWidget = new QTableWidget;
QTableWidgetItem *item = new QTableWidgetItem("My Item");
Qt::ItemFlags flags;
tableWidget ->setRowCount(1);
tableWidget ->setColumnCount(1);
tableWidget ->setItem(0, 0, item);
// set the item editable
item = tableWidget->item(0, 0);
flags = item->flags();
flags |= Qt::ItemIsSelectable | Qt::ItemIsEditable; // set the flag
item->setFlags(flags);
// set the item non-editable (view only), but still selectable
item = tableWidget->item(0, 0);
flags = item->flags();
flags |= Qt::ItemIsSelectable;
flags &= ~Qt::ItemIsEditable; // reset/clear the flag
item->setFlags(flags);
// set the item non-editable (view only), and non-selectable
item = tableWidget->item(0, 0);
flags = item->flags();
flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag
item->setFlags(flags);
To copy to clipboard, switch view to plain text mode
Bookmarks