From kde-core-devel Sun Aug 30 20:57:06 2009 From: Albert Astals Cid Date: Sun, 30 Aug 2009 20:57:06 +0000 To: kde-core-devel Subject: Re: KMenu weirdness with accelerator char Message-Id: <200908302257.06385.aacid () kde ! org> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=125166588502434 A Dissabte, 29 d'agost de 2009, Martin Koller va escriure: > Hi, > > I've got a problem with KMenu (in kmail) in trunk: > It inserts a list of strings for some actions (in this case each string is > an email address). Whenever the result of menu.exec() is asked for its > text(), the text contains an "&" accelerator character. > > Using the same code but just QMenu instead, does not show this behavior. > I looked through KMenu's code but couldn't find the problem (as > setKeyboardShortcutsEnabled is OFF by default) > > Code: > > KMenu menu( this ); > menu.setObjectName( "Addresschooser" ); > for ( QStringList::const_iterator it = emails.begin(), end = emails.end() > ; it != end; ++it ) { > kDebug() << *it; > menu.addAction( *it ); > } > const QAction *result = menu.exec( QCursor::pos() ); > if ( !result ) > return; > kDebug() << "result:" << result->text(); > > > The debug output: > kmail(7045) KMLineEdit::insertEmails: "martin.koller@etm.at" > kmail(7045) KMLineEdit::insertEmails: "koller@etm.at" > kmail(7045) KMLineEdit::insertEmails: "martin.b.koller@siemens.com" > kmail(7045) KMLineEdit::insertEmails: result: "&koller@etm.at" Yes, that is correct, menu entries for KDE have accelerator to make them easier to use to the end user, you should not expect the text you enter is the same you will get, as Michael says you can use KLocale::removeAcceleratorMarker to get a string without accelators, if you REALLY don't want your widget do be autoaccelerated, use KAcceleratorManager::setNoAccel Albert