Results 1 to 8 of 8

Thread: Raise key pressed event when button is clicked?

  1. #1
    Join Date
    May 2009
    Location
    Sweden
    Posts
    14
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Raise key pressed event when button is clicked?

    Hi,
    I'm developing an embedded Qt application where the only input method will be using the touchscreen and have made a virtual keyboard mapped with QSignalMapper. When a user presses (touches, clicks) a button on the virtual keyboard I would like the same behaviour as if a real keyboard was used. How do I do that? I figure it should be something like:

    Qt Code:
    1. void Widget::keySelected (const QString& key) {
    2. int i = key.at(0).toAscii();
    3. QKeyEvent::QKeyEvent ( QEvent::KeyPress, i, Qt::NoModifier, key, false, 1);
    4. }
    To copy to clipboard, switch view to plain text mode 
    But that doesn't work.

    The following code:
    Qt Code:
    1. void Widget::keySelected (const QString& key) {
    2. qDebug() << key;
    3. }
    To copy to clipboard, switch view to plain text mode 
    gives the output of the keyvalue, e.g. "A" if the A-button is pressed.

    Would be greatful if someone has a hint here
    Last edited by newstead; 4th June 2009 at 10:07.

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Raise key pressed event when button is clicked?

    i think this thread will be useful to u .. but may solve your problem .. try this
    http://www.qtcentre.org/forum/f-newb...ner-20799.html
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    May 2009
    Location
    Sweden
    Posts
    14
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Raise key pressed event when button is clicked?

    I'm afraid that didn't help. The problem isn't catching the events, but to raise new ones.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Raise key pressed event when button is clicked?

    You can use QCoreApplication::sendEvent()/QCoreApplication::notify()/QCoreApplication::postEvent() for that. Theoretical, because once I tried to send mous event in a graphics scene I failed, but the case was a bit of complexer.

  5. #5
    Join Date
    May 2009
    Location
    Sweden
    Posts
    14
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Raise key pressed event when button is clicked?

    Quote Originally Posted by Lykurg View Post
    You can use QCoreApplication::sendEvent()/QCoreApplication::notify()/QCoreApplication::postEvent() for that. Theoretical, because once I tried to send mous event in a graphics scene I failed, but the case was a bit of complexer.
    Thanks! That works fine. Only problem is that it overwrites existing text and not adding the new letter. Why is that?

    Just to clarify, do I really need to write a eventhandler for each widget that are going to use the virtual keyboard? Isn't there any way to just simulate a physical keyboard and use Qt:s generic inputeventhandlers?
    Last edited by newstead; 4th June 2009 at 14:12.

  6. #6
    Join Date
    May 2009
    Location
    Sweden
    Posts
    14
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Raise key pressed event when button is clicked?

    Nobody with any ideas?

  7. #7
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Raise key pressed event when button is clicked?

    download the QtExtended source code.

    go to
    src/plugins/inputmethods/keyboard

    there they have implemented a virtual keyboard. this may help

  8. The following user says thank you to nish for this useful post:

    newstead (5th June 2009)

  9. #8
    Join Date
    May 2009
    Location
    Sweden
    Posts
    14
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Raise key pressed event when button is clicked?

    Quote Originally Posted by MrDeath View Post
    download the QtExtended source code.

    go to
    src/plugins/inputmethods/keyboard

    there they have implemented a virtual keyboard. this may help
    They use the QWSServer to send keyevents which obviously doesn't work on the desktop. It would have been convienient to be able to use some sort of generic Qt-feature for future reuse but I'll guess I have to go with QWSServer for now... thanks.

Similar Threads

  1. Hot plug and button event
    By kpmsivachand in forum Qt Programming
    Replies: 6
    Last Post: 16th July 2013, 06:49
  2. Replies: 4
    Last Post: 19th February 2009, 11:10
  3. button background color when it is clicked
    By navi1084 in forum Qt Programming
    Replies: 4
    Last Post: 9th December 2008, 15:02
  4. Getting the row for button pressed
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2007, 15:45
  5. Mouse Over event on button
    By vishal.chauhan in forum Qt Programming
    Replies: 9
    Last Post: 10th January 2007, 05:03

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.