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. [SOLVED] QKeySequence only for one widget
Qt 6.11 is out! See what's new in the release blog

[SOLVED] QKeySequence only for one widget

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.9k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello everyone!
    I have MainWindow with WebView in it, StatusBar and Subclassed QFrame widget on StatusBar.
    in my QFrame widget I create action for key sequence as follow:
    @
    ExSearchBar::ExSearchBar(QWidget *parent):QFrame(parent)
    {

    .....

    QKeySequence keys_esc(Qt::Key_Escape);
    this->esc = new QAction(this);
    connect(this->esc, SIGNAL(triggered()), this, SLOT(search_hide()));
    this->esc->setShortcut(keys_esc);
    this->addAction(this->esc);
    }
    @

    The problem is, what the action triggers even if currently active(focused) widget is WebView(or WebFrame)...
    How can I restrict this QKeySequence action only for widget it is created for?(Should be triggered only when widget or its childs are in focus)

    Thanks in advance!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      d2uriel
      wrote on last edited by
      #2

      Try changing the "shortcut context":http://qt-project.org/doc/qt-4.8/qaction.html#shortcutContext-prop .

      "Do not judge, and you will never be mistaken." - Jean-Jacques Rousseau

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rschaub
        wrote on last edited by
        #3

        you should set the shortcutContext to 'Qt::WidgetShortcut', which will enable the action only if the widget itself has focus, but not any of its children.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @
          ExSearchBar::ExSearchBar(QWidget *parent):QFrame(parent)
          {
          .....

          QKeySequence keys_esc(Qt::Key_Escape);
          this->esc = new QAction(this);
          connect(this->esc, SIGNAL(triggered()), this, SLOT(search_hide()));
          this->esc->setShortcut(keys_esc);
          this->esc->setShortcutContext(Qt::WindowShortcut);
          this->addAction(this->esc);
          }@

          Doesn't work... it is still triggered.. . and this->hasFocus() is false...

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rschaub
            wrote on last edited by
            #5

            you set the shortcutContxt to 'WindowShortcut' which is the default, meaning the behaviour shouldn't have changed.

            Try changing it to 'Qt::WidgetShortcut'.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              My bad :) Thank you guys! Works!

              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