PDA

View Full Version : dynamic keyboard shortcuts troubles



gadnio
31st March 2006, 08:58
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:


//-----------------------------------------------------------------------------
void n_dv_frame::set_accel_key( n_qt_property * prop, const QChar & accel )
{
QKeySequence seq( QString( "Alt+" ) + accel );
int id = f_accel->findKey( seq );
if ( id == -1 )
{
id = f_accel->insertItem( seq );
}
f_accel->connectItem( id, prop, SLOT( setFocus() ) );
}

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


QKeySequence seq( ALT + UNICODE_ACCEL + accel.unicode() );

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?

dimitri
16th April 2006, 10:48
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:

QKeySequence seq(QString( "Alt+" ) + accel);
but don't use this:

QKeySequence seq("Alt+" accel.unicode());
or this:

QKeySequence seq("Alt+" accel.utf8());

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?