Results 1 to 5 of 5

Thread: Shortcut depending on the language

  1. #1
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

    Default Shortcut depending on the language

    Hi,

    I have a QT application with a large text, and I would like to show a 'Search' box when user clicks the system shortcut for this functionality. But this shortcuts depends on the current system language. I mean for example, in Windows + English, Search = "CRTL + F", but in Windows + Spanish, Search = "CRTL + B".

    How can I manage this issue and detect the good shorcut depending on the language? I would like to open my 'Search' box when the user presses CRTL+F (if system is in English), or when user presses CTRL+B (if system is in Spanish)

    Thanks in advance,
    Diego

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Shortcut depending on the language

    Hi,

    You can use QLocale for this:
    Qt Code:
    1. QLocale qLocale = QLocale::system(); //Get the system locale
    2. QLocale::Country qCountry = qLocale.country();
    3. QLocale::Language qLanguage = qLocale.country();
    4.  
    5. //Here you can play with "qCountry" and "qLanguage" variables to change the shortcut of your QAction to the correct key combination. Think on that in you can have multiple languages into the same country(Spain have Spanish,Catalan,Basque,Galician,...)
    6. qMyAction.setShortcut(...);
    To copy to clipboard, switch view to plain text mode 
    Òscar Llarch i Galán

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Shortcut depending on the language

    QKeySequence, which is usually used to define such keyboard combinations, e.g. on a QAction or a QShortcut, supports translations.

    I.e. you can pass the string like "CTRL+F" through the Qt translation funcion tr() and it will be part of what a translator can adapt.

    In that special case of search/find, there is also a predefined standard key, see "Find" in http://doc.qt.io/qt-5/qkeysequence.h...andardKey-enum

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:

    ^NyAw^ (22nd December 2016)

  5. #4
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Shortcut depending on the language

    Thanks a lot for the response. I forgot to say (sorry!!!) that my application has QML, I don't use QWidgets for GUI. I have tried:

    Shortcut {
    sequence: StandardKey.Find
    context: Qt.ApplicationShortcut
    onActivated: console.log("find...")
    }

    But 'onActivated' is only called with CTRL+F (not depending on the language)

  6. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Shortcut depending on the language

    Ok, strange.

    Have you verified that the correct translation for Qt is loaded?

    If it is and still does not work, try the translatable string approach
    Qt Code:
    1. sequence: qsTr("CTRL+F")
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. rotating through bitmaps depending on event
    By Speerfish in forum Qt Programming
    Replies: 0
    Last Post: 3rd January 2014, 16:45
  2. Depending Combobox
    By cia.michele in forum Qt Programming
    Replies: 1
    Last Post: 10th January 2012, 17:11
  3. how to get font width depending on its scale
    By iceman in forum Qt Programming
    Replies: 0
    Last Post: 28th July 2010, 06:50
  4. Table with number of columns depending on row?
    By Arghargh in forum Qt Programming
    Replies: 3
    Last Post: 29th May 2008, 13:03
  5. Displaying windows depending on checkboxes
    By Salazaar in forum Newbie
    Replies: 1
    Last Post: 12th May 2007, 19:42

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
  •  
Qt is a trademark of The Qt Company.