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. Replacing GetAsyncKeyState in painting code
Forum Updated to NodeBB v4.3 + New Features

Replacing GetAsyncKeyState in painting code

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 459 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    I'm converting some Windows code that has the following in the repainting code:

    bool forceHere  = (GetAsyncKeyState(VK_SHIFT) & 0x8000);
    

    The intention is that if the shift key is pressed at this time, then things are drawn a little differently.

    I think that I can remove the call to GetAsyncKeyState(), and change forceHere from being a local variable to be a member variable, I could then write a MouseMove handler like this:

    void ClassName::mouseMoveEvent(QMouseEvent* e)
    {
    	if (e->modifiers() & Qt::ShiftModifier)
    		forceHere = true;
    	else
    		forceHere = false;
    
    	update();
    }
    

    which I think would have the same end result. Is that correct?

    Thanks
    David

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You can also check the modifier state during your paintEvent.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #3

        At least on Qt 5.5 I get:

        error C2039: 'modifiers': is not a member of 'QPaintEvent'

        D.

        Christian EhrlicherC 1 Reply Last reply
        0
        • PerdrixP Perdrix

          At least on Qt 5.5 I get:

          error C2039: 'modifiers': is not a member of 'QPaintEvent'

          D.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Perdrix said in Replacing GetAsyncKeyState in painting code:

          error C2039: 'modifiers': is not a member of 'QPaintEvent'

          And that's correct. It's a function of QGuiApplication as properly documented.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved