Results 1 to 2 of 2

Thread: QKeyPress - Simulating key press

  1. #1
    Join Date
    Mar 2018
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QKeyPress - Simulating key press

    https://www.qtcentre.org/threads/153...keyboard-press


    I tried the same approach, but not able to get written on the lineEdit widget

    Qt Code:
    1. ui->lineEdit->setFocus();
    2. QKeyEvent *key_press = new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_X, Qt::NoModifier);
    3. QApplication::sendEvent(ui->lineEdit, key_press);
    To copy to clipboard, switch view to plain text mode 

    Alternately

    Qt Code:
    1. QApplication::postEvent(ui->lineEdit, key_press);
    To copy to clipboard, switch view to plain text mode 
    also didn't succeed.

    I tried the below also and didn't get any result.

    Qt Code:
    1. QKeyEvent key(QEvent::KeyPress, Qt::Key_X, Qt::NoModifier);
    2. QApplication::sendEvent(ui->lineEdit, &key);
    3. if (key.isAccepted()) {
    4. qDebug()<<"everything is ok";
    5. } else {
    6. qDebug()<<"something wrong";
    7. }
    To copy to clipboard, switch view to plain text mode 
    Please suggest what am I missing.

    Regards,
    Sayan

  2. #2
    Join Date
    Mar 2018
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QKeyPress - Simulating key press

    Hi,
    got it done.

    ui->lineEdit->setFocus();
    QKeyEvent *key_press = new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_X, Qt::NoModifier, "x");
    QApplication::sendEvent(ui->lineEdit, key_press);
    the last parameter ..

Similar Threads

  1. Simulating mouse clicks
    By bvox in forum Qt Programming
    Replies: 1
    Last Post: 15th July 2017, 19:42
  2. Simulating a console window
    By Doug Broadwell in forum Newbie
    Replies: 3
    Last Post: 18th February 2011, 16:30
  3. Simulating item selection in QTreeView.
    By chandan in forum Newbie
    Replies: 4
    Last Post: 5th October 2010, 13:56
  4. Simulating a Button Click signal
    By Ratheendrans in forum Qt Programming
    Replies: 4
    Last Post: 5th May 2010, 12:57
  5. QKeyPress or ReleaseEvent
    By hgedek in forum Qt Programming
    Replies: 5
    Last Post: 19th October 2007, 15:26

Tags for this Thread

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.