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. problems with getting keypress event
Forum Updated to NodeBB v4.3 + New Features

problems with getting keypress event

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.3k 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.
  • D Offline
    D Offline
    django.Reinhard
    wrote on last edited by
    #1

    Hi,

    here's my actual question (before I was shocked by Qt's stylesheet handling)

    I have these widgets:
    FE_styles09.jpg
    The green area is a notebook-page, which manages 10 (child-)editors. Each editor has lineedits.
    All but one editors are disabled and an editor can be selected by CTRL+number

    The notebook-widget is part of a widget stack, so not always visible. That was the reason for me, not to use default tab shortcuts but instead overload keypressEvent.
    I can use ALT+number to change current tab.

    Now when the editor-page is active, key-events go into lineedit. Then the editor gets a keypressEvent and the container widget, that holds all editors. But after that widget, key-events are routed to mainwindow.

    I found no chance for the notebook widget, to see those keystrokes. I wanted to pass keypressEvent to parent of container widget, but keypressEvent is protected. (Between notebook and editor-manager there are several internal widgets like scrollarea, internal widget, ...

    Passing key-event to widgets parent does not work and I guess, same is true, if I wonna route the key-event from mainwindow to center widget (the widget stack).

    Any hints, how the notebook could see those key-events?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can use an event filter.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • D Offline
        D Offline
        django.Reinhard
        wrote on last edited by
        #3

        Thank you for the pointer!

        I had completely forgotten about that possibility. I used it in my first prototypes - long time ago :/

        ... in this case it did not help to get the desired result. Too many widgets between notebook and lineedit.
        But it was very helpful any way!

        It bothered me that even with Ctrl or Alt modifiers the number-/letter-keys produce an input in the lineedit.
        With the event filter I was able to iron out the flawed concept.

        First I did not like that I now have to code the access keys of the notebook in the editor. But after a short thought I realized that actually every input field needs an EventFilter to not process number and letter keys with modifiers as input.

        This kind of workaround is ok for me now ;)

        It works like this:

        • editor adds itself as eventfilter to lineedit
        • editor checks for modifiers at keypress
        • if a modifier is active, editor calls keyPressEvent followed by return true - without modifiers active eventFilter returns false, which leads to default key processing of lineedit. Those keys don't arrive at keyPressEvent.

        keyPressEvent routes keys that will not be processed to its superclass. This will route key events to QMainWindow (I checked that by following timecode of event).
        As its not possible to route events to widgets parents, it was possible to distribute events top down, as all classes are my classes.

        So I changed keyPressEvent to public.
        After that change, QMainWindow passes unprocessed key events to center widget (which in my case is a stacked layout). As I manage all stacked pages with an individual class, it was easy to change keyPressEvent to public too.
        The stacked widget manager then distributes key events to the active page (widget), which in this case is the notebook.

        It's a big detour until the event reaches its destination, but it 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