QWidget::grabKeyboard() and QAction shortcuts?
-
I have a
QTableView
on which I've enabled direct cell editing, using a subclass ofQItemDelegate
withcreateEditor()
,setEditorData()
,setModelData()
, andupdateEditorGeometry()
overridden.The problem happens while a
QLineEdit
has been spawned withcreateEditor()
, and I try to hit theQt::Key_Return
key to complete editing. The app also has aQAction
withQt::Key_Enter
andQt::Key_Return
set up as shortcuts. Even if I callgrabKeyboard()
on theQLineEdit
created withincreateEditor()
, theQLineEdit
doesn't see theQt::Key_Return
key; it's consistently interpreted as a top-level application shortcut, with no apparent way to disable this (short of temporarily dispensing of the shortcut in the relevantQAction
).Digging around in the source, my guess is that
QGuiApplicationPrivate::processKeyEvent()
may need to test that either its window, or no window at all, has grabbed the keyboard before callingQWindowSystemInterface::handleShortcutEvent()
. But that may be too heavy-handed of a solution.Is this a bug in Qt? Or is this the expected behavior? If not, what is the right way to handle this?
I'm running Qt 5.15.2, if that makes any difference.
-
The plot thickens...
Until I get a resolution to my original question, I decided to remove the misfiring shortcut during the time an editor (e.g. the abovementioned
QLineEdit
) is being shown. To detect when it closes, I created a subclass ofQLineEdit
and overrode thecloseEvent()
method. But that never gets called!I eventually found the
QAbstractItemDelegate::closeEditor
signal, and that seems to reliably report when a cell-editor closes.But...how does a widget get closed without an associated close-event? Is there some other way to reliably detect when a widget gets closed?