summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qaction.cpp
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-07-22 13:14:29 +0200
committerPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-07-23 09:40:54 +0000
commita09b41bc9fc2bc6c837057f303fd82b19c6f5413 (patch)
tree0a677776ea65e068f6dcfd8cd3352937cc69bf30 /src/widgets/kernel/qaction.cpp
parentbfe4bca4986c033347d880e9bd3375f81093172b (diff)
Fix action shortcuts for QToolButton
Reverting change 4db5d3ccd17d448b59db491e2f261892f31fec74, since it introduced two separate regressions: 1. QToolButton would prefer text() over iconText() 2. Actions with a mnemonic would create a shortcut when added to a tool button. There is a fundamental problem here, which is impossible to solve correctly: A menu item with the text "Short&cut" will create a mnemonic, i.e. it will be triggered by pressing 'c' when the menu is open. However, a button with the text "Short&cut" will create a shortcut that is triggered by Alt+C as long as the window has focus. Also, iconText() is used for tool tips, so it should not contain shortcut related '&'s. This patch attempts to find a sensible compromise: 1. If the text is set through QAction::setText(), QToolButton will not create a shortcut, and will not display an underline. 2. Using QAction::setIconText("Short&cut") will create the shortcut. 3. Tooltips will not show any extra '&'s when generated from text(), but when using setIconText() directly, any '&' characters used to create shortcuts will also be visible in the tooltip. Task-number: QTBUG-23396 Task-number: QTBUG-47306 Change-Id: Ieea2fc569807c862ca462349bf91922a4029700f Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Diffstat (limited to 'src/widgets/kernel/qaction.cpp')
-rw-r--r--src/widgets/kernel/qaction.cpp11
1 files changed, 3 insertions, 8 deletions
diff --git a/src/widgets/kernel/qaction.cpp b/src/widgets/kernel/qaction.cpp
index 9fbcf28aad..4dd10720d6 100644
--- a/src/widgets/kernel/qaction.cpp
+++ b/src/widgets/kernel/qaction.cpp
@@ -58,14 +58,9 @@ QT_BEGIN_NAMESPACE
static QString qt_strippedText(QString s)
{
s.remove( QString::fromLatin1("...") );
- int i = 0;
- while (i < s.size()) {
- ++i;
- if (s.at(i-1) != QLatin1Char('&'))
- continue;
- if (i < s.size() && s.at(i) == QLatin1Char('&'))
- ++i;
- s.remove(i-1,1);
+ for (int i = 0; i < s.size(); ++i) {
+ if (s.at(i) == QLatin1Char('&'))
+ s.remove(i, 1);
}
return s.trimmed();
}