2

I am creating a QPushButton as follows, with no explicit shortcut (&):

testButton = new QPushButton(tr("Start"));

I can correctly read the button's text just after its construction:

testButton.text() returns 'Start' (without single quotes)

Then I create a signal/slot connection:

QObject::connect( testButton, &QPushButton::clicked, this, &Dialog::actionRequest );

In the Dialog::actionRequest slot, testButton.text() returns '&Start', as if a shortcut had been created "somewhere", under the hood.

If I name the button 'Foo', the same phenomenon occurs, but testButton.text() would return 'F&oo'. That's because I already have a "File" menu, that has an explicit shortcut -- created as:

fileMenu = new QMenu(tr("&File"), this);

and, possibly, Alt+O would be the next "available" shortcut?

I do not want this implicit shortcut creation for my QPushButton. What's the solution to this problem? I'm running Fedora 22 ( with plasma 5), with stock qt 5.5 packages.

mamahuhu
  • 311
  • 2
  • 10
  • 1
    Thanks a lot! So it seems to be a "bug" in kde (or at least an "unwanted" feature in my point of view!) – mamahuhu Oct 07 '15 at 18:49

1 Answers1

0

There is a default QShortcut object associated with menu options, buttons, etc. Unfortunately there is no way to directly access and disable them after creation that I know of.

You can attempt to call the Qt global function qt_set_sequence_auto_mnemonic(false); to disable this behavior dynamically but I'm not sure if it's available on every platform.

AJG85
  • 15,849
  • 13
  • 42
  • 50