Results 1 to 5 of 5

Thread: Key event problems

  1. #1
    Join Date
    Dec 2015
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Key event problems

    Hey And Happy New Year!

    I'm doing little 2D game with PyQt5. This game can be played in 2-4 player group at the same time and on the same keyboard. Every player has own four keys for moving UP/DOWN/LEFT/RIGHT.

    Here are the questions:

    Is it possible to handle many same time pressed keys in PyQt5? e.g. I'm having two players with their own keys. I want to press UP and RIGHT buttons on both players at the same time. Both players should move to north-east at the same time.

    Is it possible to remove the time gap between very first key press and AutoRepeat? I want it to repeat the key event from very beginning of the key press without any little stops (That stop takes about 200ms but it's very notable stop in the game where players should move smoothly).

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Key event problems

    Key events are fired independently, so you just need to modify your state whenever one happens.

    Instead of auto repeat I would just toggle on key press / release and use a timer for "repeat".

    Cheers,
    _

  3. #3
    Join Date
    Dec 2015
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Key event problems

    Actually one more question

    Can each QGraphicsItem (player) handle own events in own event side? Is it possible to focus on two event sides at the same time? e.g. There are two players, so there are two QGraphicsItems and both QGraphicsItem has keyPressEvent and keyReleaseEvent. Can their events be handled as separated ones or do I have to get them to one side? I tried this little bit but just one of them moved.
    Last edited by QT_NUB; 1st January 2016 at 14:25.

  4. #4
    Join Date
    Dec 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Key event problems

    Hey QT_NUB,

    it woukd be usefull to see some code ;-)

    Max

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Key event problems

    Quote Originally Posted by QT_NUB View Post
    Can each QGraphicsItem (player) handle own events in own event side?
    While each item could implement its own event handling, only one would receive key events at any given time (i.e. would have the keyboard focus).

    What you need instead is event handling at the scene level.

    Cheers,
    _

Similar Threads

  1. Event Filter doesnt work on Drop Event
    By DNW in forum Qt Programming
    Replies: 3
    Last Post: 25th October 2015, 06:55
  2. Mac Plugin Event Loop Problems
    By grant in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2013, 10:33
  3. Replies: 10
    Last Post: 15th January 2010, 14:35
  4. how to combine keypress event and mousebuttonpress event?
    By hildebrand in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2009, 23:08
  5. Replies: 0
    Last Post: 23rd October 2008, 12:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.