QWidget::grabKeyboard() and QAction shortcuts?
-
I have a
QTableViewon which I've enabled direct cell editing, using a subclass ofQItemDelegatewithcreateEditor(),setEditorData(),setModelData(), andupdateEditorGeometry()overridden.The problem happens while a
QLineEdithas been spawned withcreateEditor(), and I try to hit theQt::Key_Returnkey to complete editing. The app also has aQActionwithQt::Key_EnterandQt::Key_Returnset up as shortcuts. Even if I callgrabKeyboard()on theQLineEditcreated withincreateEditor(), theQLineEditdoesn't see theQt::Key_Returnkey; 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 ofQLineEditand overrode thecloseEvent()method. But that never gets called!I eventually found the
QAbstractItemDelegate::closeEditorsignal, 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?