0

I want to make items of QTableWidget editable for user. The following code works perfectly when it is compiled within a separate project:

QTableWidget *tablewidget = new QTableWidget;

// Add data
tablewidget->insertRow(0);
tablewidget->insertColumn(0);
tablewidget->insertColumn(1);

QTableWidgetItem *item;
item = new QTableWidgetItem("editable");
tablewidget->setItem(0,0,item);

I can double click to cell and it becomes ready to receive keys.

But when I make this code a part of my existing project (exactly this code, no difference and no connections to existing code), double click on cell causes nothing - cell is not editable!

This project is really big and full code review will take enormous amount of time.

My first assumption - maybe Qt allows globally set non-editable state for all instances of QTableWidget/QTableWidgetItem? Or register delegates globally?

What do you think root cause is?

tmporaries
  • 1,523
  • 8
  • 25
  • 39

1 Answers1

0

The QTableWidget is editable by default and have DoubleClick as edit trigger.

But your already existing project may have changed these properties. You can change them to default. First try setting edit trigger for the whole table:

tableWidget->setEditTriggers(QAbstractItemView::DoubleClicked);

If it doesn't solve your problem, then try changing each item's editable property:

item->setFlags(item.Flags() | Qt::ItemIsEditable);
Mousa
  • 2,190
  • 3
  • 21
  • 34