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. Is there a way to send a key press to a widget without having to move the mouse over it?
Forum Updated to NodeBB v4.3 + New Features

Is there a way to send a key press to a widget without having to move the mouse over it?

Scheduled Pinned Locked Moved Unsolved General and Desktop
28 Posts 8 Posters 6.6k Views 4 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.
  • L Offline
    L Offline
    lachdanan
    wrote on last edited by
    #19

    @mrjj said in Is there a way to send a key press to a widget without having to move the mouse over it?:

    dumpObjectTree

    Thanks, I have to check that viewport method, I didn't see that before.

    Basically I tried another widget I normally work on and that accepted the key. But this widget, no key I sent, were accepted.

    I call dumpObjectTree method but it doesn't print anything, I guess it only works in IDE environments?

    But I acquire the widget currently using widgetAt method and after that I recursively gathered all of its children which are these:

    <PySide2.QtWidgets.QWidget object at 0x000000006CDA9DC8>
    [<PySide2.QtWidgets.QWidget object at 0x000000006CDA9DC8>, <PySide2.QtWidgets.QWidget object at 0x000000009B3FC508>, <PySide2.QtWidgets.QWidget object at 0x000000006CDA9E88>, <PySide2.QtWidgets.QWidget object at 0x000000009B5E6A88>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B42B948>, <PySide2.QtWidgets.QWidget object at 0x000000009B42B7C8>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B42B108>, <PySide2.QtWidgets.QWidget object at 0x000000009B42B1C8>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B42BFC8>, <PySide2.QtWidgets.QWidget object at 0x000000009B2A2D88>, <PySide2.QtWidgets.QWidget object at 0x000000009B316CC8>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B316D08>, <PySide2.QtWidgets.QWidget object at 0x000000009B40FDC8>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B316BC8>, <PySide2.QtWidgets.QWidget object at 0x000000009B316C08>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B316A08>, <PySide2.QtWidgets.QWidget object at 0x000000009B3169C8>, <PySide2.QtWidgets.QWidget object at 0x000000009B3174C8>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B3170C8>, <PySide2.QtWidgets.QWidget object at 0x000000009B317848>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B317388>, <PySide2.QtWidgets.QWidget object at 0x000000009B3173C8>, <PySide2.QtWidgets.QWidget object at 0x000000009B317A48>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B3175C8>, <PySide2.QtWidgets.QWidget object at 0x000000009B317148>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B317D88>]

    Not sure if that helps. Unfortunately in this app, this is how you have to blindly find the widget you are looking for.

    mrjjM 1 Reply Last reply
    0
    • L lachdanan

      @mrjj said in Is there a way to send a key press to a widget without having to move the mouse over it?:

      dumpObjectTree

      Thanks, I have to check that viewport method, I didn't see that before.

      Basically I tried another widget I normally work on and that accepted the key. But this widget, no key I sent, were accepted.

      I call dumpObjectTree method but it doesn't print anything, I guess it only works in IDE environments?

      But I acquire the widget currently using widgetAt method and after that I recursively gathered all of its children which are these:

      <PySide2.QtWidgets.QWidget object at 0x000000006CDA9DC8>
      [<PySide2.QtWidgets.QWidget object at 0x000000006CDA9DC8>, <PySide2.QtWidgets.QWidget object at 0x000000009B3FC508>, <PySide2.QtWidgets.QWidget object at 0x000000006CDA9E88>, <PySide2.QtWidgets.QWidget object at 0x000000009B5E6A88>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B42B948>, <PySide2.QtWidgets.QWidget object at 0x000000009B42B7C8>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B42B108>, <PySide2.QtWidgets.QWidget object at 0x000000009B42B1C8>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B42BFC8>, <PySide2.QtWidgets.QWidget object at 0x000000009B2A2D88>, <PySide2.QtWidgets.QWidget object at 0x000000009B316CC8>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B316D08>, <PySide2.QtWidgets.QWidget object at 0x000000009B40FDC8>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B316BC8>, <PySide2.QtWidgets.QWidget object at 0x000000009B316C08>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B316A08>, <PySide2.QtWidgets.QWidget object at 0x000000009B3169C8>, <PySide2.QtWidgets.QWidget object at 0x000000009B3174C8>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B3170C8>, <PySide2.QtWidgets.QWidget object at 0x000000009B317848>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B317388>, <PySide2.QtWidgets.QWidget object at 0x000000009B3173C8>, <PySide2.QtWidgets.QWidget object at 0x000000009B317A48>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B3175C8>, <PySide2.QtWidgets.QWidget object at 0x000000009B317148>, <PySide2.QtWidgets.QVBoxLayout object at 0x000000009B317D88>]

      Not sure if that helps. Unfortunately in this app, this is how you have to blindly find the widget you are looking for.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #20

      Hi

      But this widget, no key I sent, was accepted.

      Ok so that often would mean that its not the right widget we send to.
      It should work the same (event wise) regardless of the widget but
      if nothing happens it smell like it's not hooked up as we think or similar.

      • I call dumpObjectTree method but it doesn't print anything, I guess it only works in IDE environments?
        Oh, i assumed it uses the qDebug method as it comes the same place but you could be right.

      Hmm,. it only shows QVBoxLayout names.
      Do/can you call widgetprt->metaObject()->className()
      so we maybe could see the it better ?

      Also just to be sure. We are talking about this one
      alt text

      One thing I might try if all else fails is to install an event filter (if that works in python)
      on the ListView (or what it is )
      and see what is sent to it when you press the key.

      L 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi

        But this widget, no key I sent, was accepted.

        Ok so that often would mean that its not the right widget we send to.
        It should work the same (event wise) regardless of the widget but
        if nothing happens it smell like it's not hooked up as we think or similar.

        • I call dumpObjectTree method but it doesn't print anything, I guess it only works in IDE environments?
          Oh, i assumed it uses the qDebug method as it comes the same place but you could be right.

        Hmm,. it only shows QVBoxLayout names.
        Do/can you call widgetprt->metaObject()->className()
        so we maybe could see the it better ?

        Also just to be sure. We are talking about this one
        alt text

        One thing I might try if all else fails is to install an event filter (if that works in python)
        on the ListView (or what it is )
        and see what is sent to it when you press the key.

        L Offline
        L Offline
        lachdanan
        wrote on last edited by lachdanan
        #21

        @mrjj Thanks, when I call metaObject().className() I get these:

        QWidget
        QWidget
        QWidget
        QWidget
        QVBoxLayout
        QWidget
        QVBoxLayout
        QWidget
        QVBoxLayout
        QWidget
        QWidget
        QVBoxLayout
        QWidget
        QVBoxLayout
        QWidget
        QVBoxLayout
        QWidget
        QWidget
        QVBoxLayout
        QWidget
        QVBoxLayout
        QWidget
        QWidget
        QVBoxLayout
        QWidget
        QVBoxLayout

        Yes that's the panel we are talking about.

        Ok I will look into installing an event filter. I am not sure if that's supported so will have to check.

        I also just tried sending the same key events to all the child widgets but same result.

        mrjjM 1 Reply Last reply
        0
        • L lachdanan

          @mrjj Thanks, when I call metaObject().className() I get these:

          QWidget
          QWidget
          QWidget
          QWidget
          QVBoxLayout
          QWidget
          QVBoxLayout
          QWidget
          QVBoxLayout
          QWidget
          QWidget
          QVBoxLayout
          QWidget
          QVBoxLayout
          QWidget
          QVBoxLayout
          QWidget
          QWidget
          QVBoxLayout
          QWidget
          QVBoxLayout
          QWidget
          QWidget
          QVBoxLayout
          QWidget
          QVBoxLayout

          Yes that's the panel we are talking about.

          Ok I will look into installing an event filter. I am not sure if that's supported so will have to check.

          I also just tried sending the same key events to all the child widgets but same result.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #22

          Hi
          Hmm ok, that normally gives the concreate class names and not just QWidget. :)

          Ok so is that panel. and we talk about the actual tree view there?
          you have it selected (item selected) and press a key to fire the function?
          Just try to understand what/where exactly you try to trigger

          • I also just tried sending the same key events to all the child widgets but same result.

          Hmm If it is a QShortCut key, it might be registered to other parent but you say each part has
          different keys so it's valid to assume its indeed added to list directly and not higher up in the panel/area.

          Im not a python user so I cant say if event filters works. but why not. :)

          Since this a commercial project, its not possible just to ask them how to trigger this ?

          L 1 Reply Last reply
          0
          • mrjjM mrjj

            Hi
            Hmm ok, that normally gives the concreate class names and not just QWidget. :)

            Ok so is that panel. and we talk about the actual tree view there?
            you have it selected (item selected) and press a key to fire the function?
            Just try to understand what/where exactly you try to trigger

            • I also just tried sending the same key events to all the child widgets but same result.

            Hmm If it is a QShortCut key, it might be registered to other parent but you say each part has
            different keys so it's valid to assume its indeed added to list directly and not higher up in the panel/area.

            Im not a python user so I cant say if event filters works. but why not. :)

            Since this a commercial project, its not possible just to ask them how to trigger this ?

            L Offline
            L Offline
            lachdanan
            wrote on last edited by
            #23

            @mrjj said in Is there a way to send a key press to a widget without having to move the mouse over it?:

            Hi
            Hmm ok, that normally gives the concreate class names and not just QWidget. :)

            Ok so is that panel. and we talk about the actual tree view there?
            you have it selected (item selected) and press a key to fire the function?
            Just try to understand what/where exactly you try to trigger

            • I also just tried sending the same key events to all the child widgets but same result.

            Hmm If it is a QShortCut key, it might be registered to other parent but you say each part has
            different keys so it's valid to assume its indeed added to list directly and not higher up in the panel/area.

            Im not a python user so I cant say if event filters works. but why not. :)

            Since this a commercial project, its not possible just to ask them how to trigger this ?

            Actually not just tree view but the whole panel because anywhere you invoke the key it will trigger the action.

            The action I chose is called event log that will hide the tree view but show a console like control.

            I guess I could ask them also. But they might not reply also as it's more like qt which sometimes they know how to help.

            Because there qt support in this app is very slim, everything is raw.

            mrjjM 1 Reply Last reply
            0
            • L lachdanan

              @mrjj said in Is there a way to send a key press to a widget without having to move the mouse over it?:

              Hi
              Hmm ok, that normally gives the concreate class names and not just QWidget. :)

              Ok so is that panel. and we talk about the actual tree view there?
              you have it selected (item selected) and press a key to fire the function?
              Just try to understand what/where exactly you try to trigger

              • I also just tried sending the same key events to all the child widgets but same result.

              Hmm If it is a QShortCut key, it might be registered to other parent but you say each part has
              different keys so it's valid to assume its indeed added to list directly and not higher up in the panel/area.

              Im not a python user so I cant say if event filters works. but why not. :)

              Since this a commercial project, its not possible just to ask them how to trigger this ?

              Actually not just tree view but the whole panel because anywhere you invoke the key it will trigger the action.

              The action I chose is called event log that will hide the tree view but show a console like control.

              I guess I could ask them also. But they might not reply also as it's more like qt which sometimes they know how to help.

              Because there qt support in this app is very slim, everything is raw.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #24

              @lachdanan
              Ok, and you also tried to send to the top parent ? / the widget that holds the panel.
              It sounds like a QShortcut since you dont need to click menu or button.

              Yeah, they might not be able to help in support but any info regarding who owns
              the QShortcut would help.

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

                Hi,

                Since the application might be built with Qt, did you consider using GammaRay to inspect it ? Using it you might find the right widget you need and activate it directly.

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

                JonBJ 1 Reply Last reply
                2
                • mrjjM mrjj

                  @lachdanan
                  Ok, and you also tried to send to the top parent ? / the widget that holds the panel.
                  It sounds like a QShortcut since you dont need to click menu or button.

                  Yeah, they might not be able to help in support but any info regarding who owns
                  the QShortcut would help.

                  L Offline
                  L Offline
                  lachdanan
                  wrote on last edited by
                  #26

                  @mrjj said in Is there a way to send a key press to a widget without having to move the mouse over it?:

                  @lachdanan
                  Ok, and you also tried to send to the top parent ? / the widget that holds the panel.
                  It sounds like a QShortcut since you dont need to click menu or button.

                  Yeah, they might not be able to help in support but any info regarding who owns
                  the QShortcut would help.

                  Yes I just tried sending it to the mainQtWindow and placed my cursor on the right widget before running the code, same thing.

                  @SGaist said in Is there a way to send a key press to a widget without having to move the mouse over it?:

                  Hi,

                  Since the application might be built with Qt, did you consider using GammaRay to inspect it ? Using it you might find the right widget you need and activate it directly.

                  Thanks, I just looked it up, seems like a massive download but I might give this a try.

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Hi,

                    Since the application might be built with Qt, did you consider using GammaRay to inspect it ? Using it you might find the right widget you need and activate it directly.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #27

                    @SGaist
                    Hmm, does this KDAB GammaRay play with my Python/PySide2 Qt development instead of C++? Also, no Qt Creator for development, everything run through MS VSCode in Python mode?

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      MostHated
                      wrote on last edited by MostHated
                      #28
                      This post is deleted!
                      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