Hi,
Thanks for your answers,
I used the following code:
{
Qt::ItemFlags eFlags = pItem->flags();
eFlags &= ~Qt::ItemIsEditable;
pItem->setFlags(eFlags);
}
void test::initArray()
{
int nrow, ncolumn;
nrow = 10;
ncolumn = 3;
this->arr->setRowCount(nrow);
this->arr->setColumnCount(ncolumn);
list << "Col 1" << "Col 2" << "Col 3";
this->arr->setHorizontalHeaderLabels(list);
int i = 0;
while (i <= arr->rowCount())
{
this->disableEdit(newitem);
this->arr->setItem(i, 2, newitem); // 2 is the number of the column on which I disable edition
++i;
}
}
void test::disableEdit(QTableWidgetItem* pItem)
{
Qt::ItemFlags eFlags = pItem->flags();
eFlags &= ~Qt::ItemIsEditable;
pItem->setFlags(eFlags);
}
void test::initArray()
{
this->arr = new QTableWidget();
int nrow, ncolumn;
QStringList list;
nrow = 10;
ncolumn = 3;
this->arr->setRowCount(nrow);
this->arr->setColumnCount(ncolumn);
list << "Col 1" << "Col 2" << "Col 3";
this->arr->setHorizontalHeaderLabels(list);
int i = 0;
while (i <= arr->rowCount())
{
QTableWidgetItem *newitem = new QTableWidgetItem();
this->disableEdit(newitem);
this->arr->setItem(i, 2, newitem); // 2 is the number of the column on which I disable edition
++i;
}
}
To copy to clipboard, switch view to plain text mode
It works but I have to loop for every column when I want to disable edition which is kind of long.
@wysota: I understand what you said but I have no idea on how to use a custom model and QAbstractItemModel::flags() to control which cells are editable and which are not.
Do you have a link to a tutorial or some simple code sample?
Thanks for your answers.
Bookmarks