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 8569575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:22:03+00:00 2026-06-11T18:22:03+00:00

I am writing a program in Qt that looks like this: The main window

  • 0

I am writing a program in Qt that looks like this:

Screen Capture

The main window is my class Window : QWidget, it has a QGridLayout containing four other widgets (Input_Menu : QWidget and Output_Menu : QWidget, and then two Canvas : QWidget)

I would like to trigger certain events when the user strikes a key. The problem is, the Window sometimes loses focus (it goes, say to Input_Menu, or maybe a button in Input_Menu…)

I have tried the following solutions, but they seem unsatisfactory (and dirty):

  1. Give Window the focus whenever it loses it.
  2. Tell each widget who could have the focus to trigger Window‘s KeyPressEvent function (or a clone of it) whenever it receives a keyboard event.

Ideally, I would like that if a widget receives an event (say a keyboard event) and doesn’t know what to do with it, it should automatically call its parent’s event handler. I would have hoped this to be a default feature of Qt but it doesn’t look like it. On the other hand I am really confused about the whole focus thing, I don’t really get what’s going on. Can someone explain this to me: I have included a std::cout << "key pressed" << std::endl; in my Window::KeyPressEvent function. When I first run my program, it seems the focus is on the top QComboBox in Input_Menu: if I hit the Up/Down keys, I navigate in that box and no “key pressed” is showed in my console. If I hit most letters, nothing happens. But if I hit Left/Right keys, I do get a “key pressed” in my console!?

Thanks a lot in advance for your insights.

  • 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-06-11T18:22:05+00:00Added an answer on June 11, 2026 at 6:22 pm

    Actually, I found that for keys that are modifiers (such as Shift, Control), Qt supports finding out whether they are pressed.

    Eg : if(QApplication::keyboardModifiers() == Qt::ShiftModifier) …

    This is good enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a program with Qt that looks like this: The main window
I am writing a maze game program that looks like this: import java.util.*; import
Im writing a program that should read input via stdin, so I have the
I'm writing a program that handles DBs and writes any changes into ListView for
I'm writing a program that's parsing an XML file to java objects using smooks.
I'm writing a program that reads huge file (3x280 GB) and does a fitting
I am writing a program that permutes a list of names based on a
I'm writing a program that lets the user input 6 temperature readings, and then
I am writing a program that downloads images to the hard drive and then
I am writing a program that sets up a file path that I use

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.