PDA

View Full Version : Find what QTableWidgetItem is causing closeEditor(...) in my QTableWidget?



dobedidoo
4th August 2015, 16:32
Hi

I use Qt 5.4.0 and in my application I have a class (call it MyTable) derived from QTableWidget. Now I wonder if/how I can find out what cell/QTableWidgetItem that causes MyTable::closeEditor(QWidget* editor, QAbstractItemDelegate::EndEditHint hint) to be called? That is, when closeEditor(...) is entered, is there a way to find out what cell has just been edited?

Hope this could be understood.

anda_skoa
4th August 2015, 19:39
maybe describe what you want to effectively achieve. there could be other ways of doing that.

Cheers,
_

dobedidoo
4th August 2015, 21:22
Hi,
Well, basically what I need is to be able to find out what is the data (QTableWidgetItem::​data(int role)) of the item that's being edited. This is of importance for me since futher processing of the content in the cell depends on the data (in my case, role is Qt::UserRole). In some special cases, I will need to programmatically change the content of the cell, and I do not know that until I'm in MyTable::closeEditor(). At least, I cannot find a way. The QTableWidget::​cellChanged() won't do for example when I've edited the cell content but not changed it (that is, simply written the same text again as was in the cell before). I really need to know what cell has been edited (but maybe not changed) also for such cases.
Perhaps only more confusing...

anda_skoa
5th August 2015, 10:41
Sounds like what you really need is your own item delegate and overwriting setEditorData() to do your checks.

I am not sure which delegate the QTableWidget uses by default, but it is probably a QStyledItemDelegate.
So deriving from that and reimplementing the method should come close.

Cheers,
_