[Qt-interest] Fwd: Re: how to determine if Qt::Key is printable and get the according string?
noname
freekee1 at gmx.de
Mon Dec 20 11:15:30 CET 2010
On 12/20/2010 09:39 AM, Girish Ramakrishnan wrote:
> On Sun, Dec 19, 2010 at 7:29 PM, noname<freekee1 at gmx.de> wrote:
>> hi everyone!
>>
>> i can't seem to figure out how i can
>> 1. determine if a given Qt::Key value is a printable one, or just some
>> functional key
>> 2. get the according text (QChar/QString) in case it is printable.
>>
>> Maybe someone here has a solution or a hint?
>>
> Assuming you have a QKeyEvent, you have use QKeyEvent::text(). To
> check if it's printable, you can use QChar::isPrint().
>
> Girish
>
hi Girish,
thanks for the reply, but unfortunately i do not have a QKeyEvent
(actually i need this to be able to create one) ...
I found an approach, which i don't really like at all, but it's what
comes closest to what i want (still far away though ...):
QString text = QKeySequence(Qt::Key_XYZ).toString();
text = (text.length() == 1) ? text : QString();
This somehow works for most keys, but it's of course not guaranteed at
all to work, and it's obviously pretty unclean, since
QKeySequence::toString() returns (int this case) the actual label of a
key as you would see it on your keyboard, like "CapsLock", "Shift",
"Esc", ...
I'm still thankful for everyone who can give me another hint on this!
Sincerely
Julian
More information about the Qt-interest-old
mailing list