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. Key pressed in QWidget::mousePressedEvent()
Forum Updated to NodeBB v4.3 + New Features

Key pressed in QWidget::mousePressedEvent()

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.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.
  • M Offline
    M Offline
    M Wong
    wrote on last edited by
    #1

    Is there any way that let me know if the spacebar is being pressed inside QWidget::mousePressEvent() / QWidget::mouseMoveEvent() ?

    RatzzR kshegunovK 2 Replies Last reply
    0
    • M M Wong

      Is there any way that let me know if the spacebar is being pressed inside QWidget::mousePressEvent() / QWidget::mouseMoveEvent() ?

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #2

      @M-Wong
      You may try this

      void Widget::mousePressEvent(QMouseEvent *e)
      {
              if(e->button()==Qt::Key_Space) {
               e->accept();
          }
      }

      --Alles ist gut.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        M Wong
        wrote on last edited by
        #3

        @Ratzz

        Thanks for your reply.
        However I don't think your code will tell whether the SpaceBar is being pressed or not inside the mousePressEvent()...

        Anyway, I now use Win32 API -- GetKeyState() / GetAsyncKeyState() to solve the problem.

        1 Reply Last reply
        0
        • M M Wong

          Is there any way that let me know if the spacebar is being pressed inside QWidget::mousePressEvent() / QWidget::mouseMoveEvent() ?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @M-Wong

          Is there any way that let me know if the spacebar is being pressed inside QWidget::mousePressEvent() / QWidget::mouseMoveEvent() ?

          Not to my knowledge, no. But you can intercept the key-press event as well as the mouse event and set a state internally that the spacebar is pressed.

          Anyway, I now use Win32 API -- GetKeyState() / GetAsyncKeyState() to solve the problem.

          That's possible, but the implications would be you code will be working only(!) on windows and you would require the windows SDKs to build it.

          Kind regards.

          Read and abide by the Qt Code of Conduct

          M 1 Reply Last reply
          0
          • kshegunovK kshegunov

            @M-Wong

            Is there any way that let me know if the spacebar is being pressed inside QWidget::mousePressEvent() / QWidget::mouseMoveEvent() ?

            Not to my knowledge, no. But you can intercept the key-press event as well as the mouse event and set a state internally that the spacebar is pressed.

            Anyway, I now use Win32 API -- GetKeyState() / GetAsyncKeyState() to solve the problem.

            That's possible, but the implications would be you code will be working only(!) on windows and you would require the windows SDKs to build it.

            Kind regards.

            M Offline
            M Offline
            M Wong
            wrote on last edited by
            #5

            @kshegunov said:

            Not to my knowledge, no. But you can intercept the key-press event as well as the mouse event and set a state internally that the spacebar is pressed.

            Good Advice. I may try it... But I should stop programming now and get back to my real hobby -- 3DCG. ( Programming isn't even my hobby, I just need some app that's tailor-made for myself.

            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