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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:52:28+00:00 2026-05-23T16:52:28+00:00

I need to do this for configuring my application. I have QLineEdit field with

  • 0

I need to do this for configuring my application.
I have QLineEdit field with reimplemented keyPressEvent method.

QKeyEvent *ke = ...
QString txt;

if(ke->modifiers() & Qt::ControlModifier)
    txt += "Ctrl+";
if(ke->modifiers() & Qt::AltModifier)
    txt += "Alt+";
if(ke->modifiers() & Qt::ShiftModifier)
    txt += "Shift+";

if(ke->key() >= Qt::Key_0 && ke->key() <= Qt::Key_9)
    txt += ('0' + ke->key() - Qt::Key_0);
else if(ke->key() >= Qt::Key_A && ke->key() <= Qt::Key_Z)
    txt += ('A' + ke->key() - Qt::Key_A);
ui->hotkeyEdit->setText(txt);

But this solution can create shortcuts only with english chars. For example when I use russian keyboard layout, this code will display the same sequence but with english char, placed on the same keyboard key.

  • 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-23T16:52:28+00:00Added an answer on May 23, 2026 at 4:52 pm

    What you might find very useful is the function QKeySequence().toString().

    The following is a part of a code that I use to capture User Defined Shortcuts. With some modifications it can do whatever you need in your project. Hope it helps (sorry for the crapped identation):

    if (event->type() == QEvent::KeyPress){ 
        QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); 
    
        int keyInt = keyEvent->key(); 
        Qt::Key key = static_cast<Qt::Key>(keyInt); 
        if(key == Qt::Key_unknown){ 
            qDebug() << "Unknown key from a macro probably"; 
            return; 
        } 
        // the user have clicked just and only the special keys Ctrl, Shift, Alt, Meta. 
        if(key == Qt::Key_Control || 
            key == Qt::Key_Shift || 
            key == Qt::Key_Alt || 
            key == Qt::Key_Meta)
        { 
            qDebug() << "Single click of special key: Ctrl, Shift, Alt or Meta"; 
            qDebug() << "New KeySequence:" << QKeySequence(keyInt).toString(QKeySequence::NativeText); 
            return; 
        } 
    
        // check for a combination of user clicks 
        Qt::KeyboardModifiers modifiers = keyEvent->modifiers(); 
        QString keyText = keyEvent->text(); 
        // if the keyText is empty than it's a special key like F1, F5, ... 
        qDebug() << "Pressed Key:" << keyText; 
    
        QList<Qt::Key> modifiersList; 
        if(modifiers & Qt::ShiftModifier) 
            keyInt += Qt::SHIFT; 
        if(modifiers & Qt::ControlModifier) 
            keyInt += Qt::CTRL; 
        if(modifiers & Qt::AltModifier) 
            keyInt += Qt::ALT; 
        if(modifiers & Qt::MetaModifier) 
            keyInt += Qt::META; 
    
        qDebug() << "New KeySequence:" << QKeySequence(keyInt).toString(QKeySequence::NativeText); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need this because the constructor in the superclass is calling a method which
I have no experience with low level programing and I need this piece of
I have created the application in which I need to configure the connection pool.In
I need help with configuring Reporting Services. I have the ReportServer and Report Manager
I have a mission critical Perl-CGI server-side application that I need to extend or
This is my first test for Asp.Net Web Application. We have an Engine consisting
In my application I need to have periodically run background tasks (which I can
I need this for some animation effects and i remember there is a window
I need this for calling a C function from Java class (JNI) and I
I need this roadmap of a Hibernate managed object instance. First, I create an

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.