Results 1 to 2 of 2

Thread: dynamic keyboard shortcuts troubles

  1. #1
    Join Date
    Jan 2006
    Location
    Sofia, Bulgaria
    Posts
    24
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default dynamic keyboard shortcuts troubles

    Hi all,
    I want to make s.th. like Konqueror's shortcuts for my program. Because the interface is dynamic, i don't know how much "fields" (understand input data objects) will be there, so i have to generate the shortcuts on-the-fly.
    Here's an example:
    Qt Code:
    1. //-----------------------------------------------------------------------------
    2. void n_dv_frame::set_accel_key( n_qt_property * prop, const QChar & accel )
    3. {
    4. QKeySequence seq( QString( "Alt+" ) + accel );
    5. int id = f_accel->findKey( seq );
    6. if ( id == -1 )
    7. {
    8. id = f_accel->insertItem( seq );
    9. }
    10. f_accel->connectItem( id, prop, SLOT( setFocus() ) );
    11. }
    To copy to clipboard, switch view to plain text mode 
    The problem here lies with the non-english (unicode) characters. The "property" here has a QLabel associated with it, so they become a tuple. The QLabel's text is mostly non-english. (NOT unicode, i couldn't manage my program to correctly work with totally unicode strings, i had to use QString::fromUtf8() for that). So, I transform the string from unicode to the current locale which the program is running in and display the strings. So far so good. Then I try to make a shortcut to the "property" from the text that the QLabel displays. It fails for non-english shortcuts. This is the last almost-working source. I have tried with
    Qt Code:
    1. QKeySequence seq( ALT + UNICODE_ACCEL + accel.unicode() );
    To copy to clipboard, switch view to plain text mode 
    but still no luck. Any hints?

    Edited:
    ---------------------------------------------
    Okay, I finally got it: it is because of the characters i am using. I need to translate them to english ones (Key_A, Key_B, etc) to work. Is this right? And if it is, how to do it?
    Last edited by gadnio; 31st March 2006 at 09:45.

  2. #2
    Join Date
    Jan 2006
    Posts
    109
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: dynamic keyboard shortcuts troubles

    Which version of Qt is this, on which platform?

    Qt is supposed to work without problem with non-English characters. "Unicode" is not meaningful in this context, it's just the encoding used by QString internally, you shouldn't have to mess with it yourself. Therefore this should be OK:
    Qt Code:
    1. QKeySequence seq(QString( "Alt+" ) + accel);
    To copy to clipboard, switch view to plain text mode 
    but don't use this:
    Qt Code:
    1. QKeySequence seq("Alt+" accel.unicode());
    To copy to clipboard, switch view to plain text mode 
    or this:
    Qt Code:
    1. QKeySequence seq("Alt+" accel.utf8());
    To copy to clipboard, switch view to plain text mode 

    If it doesn't work for you, could you post a minimal, compilable example that reproduces the problem? Or maybe modify one of the Qt examples and reproduce the problem?

Similar Threads

  1. Replies: 5
    Last Post: 23rd February 2007, 10:23
  2. Keyboard shortcuts problem.
    By Lemming in forum Qt Programming
    Replies: 4
    Last Post: 5th April 2006, 16:12

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.