Question

I'm showing a popup menu to select some values in a QTableWidget. The lowest item is a "Modify list" entry, when I select it a new window should automatically appear and the QComboBox should vanish and the cell return to a Qt::DisplayRole state.

Now Qt has all those nice API-calls like QTableWidget.edit() and QTableWidget.editItem(), what I'm really looking for is a QTableWidget.endEditing(), preferably without specifying the index of the cell, though I could get that using this call:

table.currentIndex()

… but I don't know if I can guarantee that the current cell is the cell being edited at all times.

Is there an API to close those kind of editors?

Popup menu

Was it helpful?

Solution

QTableWidget inherits 19 public slots from QWidget. One of those is setDisabled(), which should disable input events for that widget and all of its children.

I would try:

table.setDisabled( true );
table.setDisabled( false );

Although you said it does not work for you, there is an alternative method: If you don't like that (the table loses focus, I believe), you can try using EditTriggers. For example:

table.setEditTriggers( QAbstractItemView::NoEditTriggers );

OTHER TIPS

table.setCurrentItem(None) is what worked for me. (Don’t forget to block signals if you use some cellChanged/itemChanged slot function.)

This is with PyQt. For C++ I think replace None with NULL.

You may be able to use QTableWidget.closePersistentEditor() to close the editor. However, QAbstractItemView.closeEditor() may be closer to what you want, especially since you seem to be comfortable with the QModelIndex-based API and are already using a custom editor widget.

I can't speak for list widgets. But, I got here trying to do something similar.

I was double-clicking a cell, and based on the column, bringing up a sub-form with a list, then when that was closed move to the next appropriate column based on the value selected.

My problem was I could get the value in the cell and "select" the next appropriate cell, but the original cell stayed selected in edit mode!

It finally dawned on me that my double-click was selecting the cell, ie. editing.

A single-click selects the cell but doesn't open an edit mode.

Side note: Never could get that sub-form to act truly modal, so I created a loop in the calling form: while the sub form was visible, with the only code being app.processEvents()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top