I have inherited a virtual keyboard system with an array of buttons, one for each key. The label for each button is a single QChar. When showing the "symbols" keyboard, the code uses an '&' QChar for a key label, but the key shows as blank. I'm sure Qt is processing the '&' as a shortcut key prefix. Similarly, the entered text is shown on another, longer, button label; this label, as well, handles '&' character as an accelerator. Entering "ABC&DEF" is shown as "ABCDEF" with the 'D' underlined.
I have tried building with QT_NO_SHORTCUT #defined, but that made no difference.
Does anyone know of an easy way to disable this special handling of '&'?
The answer is found in Qt doc.
QAbstractButton::text:(Emphasize by me.)
QPushButtonis derived fromQAbstractButtoninheriting this behavior.Sample
testQPushButtonAmp.cc:testQPushButtonAmp.pro:Compiled and tested on cygwin64 on Windows 10:
Concerning how to disable this default behavior:
I had a look at woboq.org
QAbstractButton::setText().So,
QT_NO_SHORTCUTdisables to retrieve the shortcut out of text but it has to be defined when Qt library is built from source. Actually, I'm afraid even with disabled shortcuts, the single&will still become invisible in output.I digged deeper in
woboq.organd found some promising candidates e.g.:qt_set_sequence_auto_menmonic()and a sample in
QProxyStylewhich I tried in my sample.
Finally, nothing of them achieved the desired effect, i.e. only
"&&"was rendered as&but"&"never.__