Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidget::grabKeyboard() and QAction shortcuts?
Forum Updated to NodeBB v4.3 + New Features

QWidget::grabKeyboard() and QAction shortcuts?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 277 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    Ulatekh
    wrote on last edited by
    #1

    I have a QTableView on which I've enabled direct cell editing, using a subclass of QItemDelegate with createEditor(), setEditorData(), setModelData(), and updateEditorGeometry() overridden.

    The problem happens while a QLineEdit has been spawned with createEditor(), and I try to hit the Qt::Key_Return key to complete editing. The app also has a QAction with Qt::Key_Enter and Qt::Key_Return set up as shortcuts. Even if I call grabKeyboard() on the QLineEdit created within createEditor(), the QLineEdit doesn't see the Qt::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 relevant QAction).

    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 calling QWindowSystemInterface::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.

    1 Reply Last reply
    0
    • U Offline
      U Offline
      Ulatekh
      wrote on last edited by
      #2

      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 of QLineEdit and overrode the closeEvent() 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?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved