From f351b00075f8f8b5ef5b355b55b9572eb0cc525c Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sun, 24 Sep 2017 15:25:57 +0300 Subject: [PATCH] Manually remove KDE accelerators fixes #14 --- src/ui/FlatButton.cc | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/ui/FlatButton.cc b/src/ui/FlatButton.cc index 4ba92a38..f2314078 100644 --- a/src/ui/FlatButton.cc +++ b/src/ui/FlatButton.cc @@ -11,6 +11,21 @@ #include "RippleOverlay.h" #include "ThemeManager.h" +// The ampersand is automatically set in QPushButton or QCheckbx +// by KDEPlatformTheme plugin in Qt5. [https://bugs.kde.org/show_bug.cgi?id=337491] +// +// A workaroud is to add +// +// [Development] +// AutoCheckAccelerators=false +// +// to ~/.config/kdeglobals +static QString +removeKDEAccelerators(QString text) +{ + return text.remove(QChar('&')); +} + void FlatButton::init() { @@ -327,7 +342,7 @@ FlatButton::sizeHint() const { ensurePolished(); - QSize label(fontMetrics().size(Qt::TextSingleLine, text())); + QSize label(fontMetrics().size(Qt::TextSingleLine, removeKDEAccelerators(text()))); int w = 20 + label.width(); int h = label.height(); @@ -500,11 +515,11 @@ FlatButton::paintForeground(QPainter *painter) } if (icon().isNull()) { - painter->drawText(rect(), Qt::AlignCenter, text()); + painter->drawText(rect(), Qt::AlignCenter, removeKDEAccelerators(text())); return; } - QSize textSize(fontMetrics().size(Qt::TextSingleLine, text())); + QSize textSize(fontMetrics().size(Qt::TextSingleLine, removeKDEAccelerators(text()))); QSize base(size() - textSize); const int iw = iconSize().width() + IconPadding; @@ -519,7 +534,7 @@ FlatButton::paintForeground(QPainter *painter) /* iconGeometry.translate(textSize.width() + IconPadding, 0); */ /* } */ - painter->drawText(textGeometry, Qt::AlignCenter, text()); + painter->drawText(textGeometry, Qt::AlignCenter, removeKDEAccelerators(text())); QPixmap pixmap = icon().pixmap(iconSize()); QPainter icon(&pixmap);