Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7046805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:41:40+00:00 2026-05-28T02:41:40+00:00

I have a custom input device on and embedded system, and have to translate

  • 0

I have a custom input device on and embedded system, and have to translate the input to proper events in Qt. In my current view I have a QListView and some QPushButtons. I use the following code in my widget.

QKeyEvent * e = NULL;
if (cmd.up.value)
    e = new QKeyEvent(QEvent::KeyPress, Qt::Key_Up, 0, 0);
else if (cmd.down.value)
    e = new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, 0, 0);
else if (cmd.left.value)
    e = new QKeyEvent(QEvent::KeyPress, Qt::Key_Left, 0, 0);
else if (cmd.right.value)
    e = new QKeyEvent(QEvent::KeyPress, Qt::Key_Right, 0, 0);
else if (cmd.ok.value)
    e = new QKeyEvent(QEvent::KeyPress, Qt::Key_Space, 0, 0);

if (e)
    QApplication::postEvent(this->focusWidget(), e);

I can move up/down/right/left between list and buttons, but I can’t click the buttons. I’ve tried using Qt::Key_Enter and Qt::Key_Return as well, but neither works.

If run the application on my pc, hitting space or the left mouse button on my keyboard gives a button click. That indicates that somewhere, the event is changed to something the pushbutton likes better than getting a Qt::Key_Space directly, right?

Anyone got an idea for how I can solve this nicely? I can check which (if any) button has focus and click it manually, but that is not very elegant coding…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:41:40+00:00Added an answer on May 28, 2026 at 2:41 am

    The solution to this was actually quite simple. A QPushButton isn’t clicked on KeyPress, but on KeyRelease. New code below.

    if (cmd.up.value)
    {
        QApplication::postEvent(this->focusWidget, 
                                new QKeyEvent(QEvent::KeyPress, Qt::Key_Up, 0, 0));
    }
    else if (cmd.down.value)
    {
        QApplication::postEvent(this->focusWidget, 
                                new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, 0, 0));
    }
    else if (cmd.left.value)
    {
        QApplication::postEvent(this->focusWidget, 
                                new QKeyEvent(QEvent::KeyPress, Qt::Key_Left, 0, 0));
    }
    else if (cmd.right.value)
    {
        QApplication::postEvent(this->focusWidget, 
                                new QKeyEvent(QEvent::KeyPress, Qt::Key_Right, 0, 0));
    }
    else if (cmd.ok.value) 
    {
        QApplication::postEvent(this->focusWidget, 
                                new QKeyEvent(QEvent::KeyPress, Qt::Key_Space, 0, 0));
        QApplication::postEvent(this->focusWidget, 
                                new QKeyEvent(QEvent::KeyRelease, Qt::Key_Space, 0, 0));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom dialog box that asks the user for some input. It's
I want to create a custom input view, some of whose buttons insert icons
I have a custom built ajax [div] based dynamic dropdown. I have an [input]
I have set my default-input-method variable to english-dvorak: (custom-set-variables '(default-input-method english-dvorak)) When I launch
I have custom coded several enterprise applications for mid to large organizations to use
Is there a way to have the custom validator take the input from two
I am using a UIWebView on iPhone to do custom input. I have the
I have added custom attribute with the code my_price with Catalog Input Type for
I have a custom control for building forms to automatically generate a label-input field
I have a custom entity in Microsoft CRM (4.0). The user has to input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.