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. Qt::Key_Down/Qt::Key_Up problem

Qt::Key_Down/Qt::Key_Up problem

Scheduled Pinned Locked Moved General and Desktop
12 Posts 5 Posters 9.1k 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #2

    It might be that these keys are captured at an earlier stage than in the keyPressEvent handler of the widget. Try installing an event filter to find out. First, try the filter on the QTreeWidget itself. If that doesn't get you the keys, install it on the QApplication.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bhamuryen
      wrote on last edited by
      #3

      Hello,
      @ void MyClass ::keyPressEvent(QKeyEvent *event)
      {
      if ( event->key () == Qt::Key_Delete ) {...}
      if ( event->key () == Qt::Key_Down ) {...}
      if ( event->key () == Qt::Key_Up ) {...}
      ...
      }
      @
      what is the event?

      try this
      @ void MyClass ::keyPressEvent(QKeyEvent *e)
      {
      if ( e->key () == Qt::Key_Delete ) {...}
      if ( e->key () == Qt::Key_Down ) {...}
      if ( e->key () == Qt::Key_Up ) {...}
      ...
      }
      @

      or

      @ class MyClass :public QTreeWidget
      {
      Q_OBJECT

      protected:
          virtual void keyPressEvent(QKeyEvent *event);
      };
      

      @

      and be sure to include the #include <QKeyEvent>

      c++ Software Developer

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #4

        bhamuryen@ I think it doesn't matter.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bhamuryen
          wrote on last edited by
          #5

          Why? I think If you want use key events it's work fine. Why is not it work?

          c++ Software Developer

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #6

            [quote author="bhamuryen" date="1364331122"]
            what is the event?
            [/quote]

            Its just a variable/instance name it does not matter if you change from QKeyEvent *event to QKeyEvent *e.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bhamuryen
              wrote on last edited by
              #7

              i now its a variable.
              this variable in header file
              @virtual void keyPressEvent(QKeyEvent *e);@
              and now in cpp file
              @void MyClass ::keyPressEvent(QKeyEvent *event)@
              two diffrent variable name. this is my main point.

              [quote author="Sam" date="1364367957"]
              [quote author="bhamuryen" date="1364331122"]
              what is the event?
              [/quote]

              Its just a variable/instance name it does not matter if you change from QKeyEvent *event to QKeyEvent *e.[/quote]

              c++ Software Developer

              1 Reply Last reply
              0
              • E Offline
                E Offline
                elibziro
                wrote on last edited by
                #8

                Thanks for all suggestions

                I think that different variable name is not a problem in my case. I have the same name in header and cpp files in my code, but still doesn't work.
                Now I will try with installing an event filter.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sam
                  wrote on last edited by
                  #9

                  @bhamuryen

                  The compiler only needs to know what kind of arguments the function requires. It's unimportant for the compiler how you call them. The function declaration only needs to specify the parameter types, order and the return type

                  you can also use
                  .h
                  @void keyPressEvent(QKeyEvent *);@

                  in you header file and it works as expected.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    bhamuryen
                    wrote on last edited by
                    #10

                    Do you have #include <QKeyEvent> in your project?

                    c++ Software Developer

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      bhamuryen
                      wrote on last edited by
                      #11

                      Ok i tried
                      virtual void keyPressEvent(QKeyEvent *e);

                      void MyClass ::keyPressEvent(QKeyEvent *event)

                      this work fine ;) . But we want to use filter (like tihs if ( e->key () == Qt::Key_Up ) {...}) we need to add the @#include <QKeyEvent>@

                      [quote author="Sam" date="1364369377"]@bhamuryen

                      The compiler only needs to know what kind of arguments the function requires. It's unimportant for the compiler how you call them. The function declaration only needs to specify the parameter types, order and the return type

                      you can also use
                      .h
                      @void keyPressEvent(QKeyEvent *);@

                      in you header file and it works as expected.[/quote]

                      c++ Software Developer

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        Sam
                        wrote on last edited by
                        #12

                        @bhamuryen

                        Yes ofcourse you need to add QKeyEvent header to your project inorder to access the member function of the class.

                        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