aboutsummaryrefslogtreecommitdiff
path: root/src/qt
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-07-15 16:36:32 +0200
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-07-15 16:48:03 +0200
commitd626a3be31d2b8ff3d5df2b39e91b1051656a28c (patch)
tree077d3c42871bbc12e2fc96f07a7772f2d9acef19 /src/qt
parent21209c9ccee888428a09d865f45d14bd40fb7686 (diff)
parentbd315eb5e27d49d47759ae9417328427426cb269 (diff)
Merge #19210: qt: Get rid of cursor in out-of-focus labels
bd315eb5e27d49d47759ae9417328427426cb269 qt: Get rid of cursor in out-of-focus labels (Hennadii Stepanov) Pull request description: After clicking on `QLabel` with selectable text the cursor remains forever: ![47532924-65e7b200-d8ba-11e8-9254-7bde658961cb](https://user-images.githubusercontent.com/32963518/84038485-ad945200-a9a8-11ea-89e3-c7c17d02a611.png) This PR fixes this visual bug. Earlier attempts to fix this issue: - #14577 - #14810 (combined with other UX feature) ACKs for top commit: promag: Code review ACK bd315eb5e27d49d47759ae9417328427426cb269. laanwj: Tested ACK bd315eb5e27d49d47759ae9417328427426cb269 Tree-SHA512: 6bf89362412e5ce9a4dec6944b62fe44fc31ca49cda7f6e2eb37e847fac9dccb68bca7ac6877b19e42add2333e40d0b4265757ead105ac0a5d28f8ab43b322c3
Diffstat (limited to 'src/qt')
-rw-r--r--src/qt/bitcoin.cpp2
-rw-r--r--src/qt/guiutil.cpp22
-rw-r--r--src/qt/guiutil.h15
3 files changed, 39 insertions, 0 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index c7dd16d2ed..a304c23a2c 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -556,6 +556,8 @@ int GuiMain(int argc, char* argv[])
/// 9. Main GUI initialization
// Install global event filter that makes sure that long tooltips can be word-wrapped
app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
+ // Install global event filter that makes sure that out-of-focus labels do not contain text cursor.
+ app.installEventFilter(new GUIUtil::LabelOutOfFocusEventFilter(&app));
#if defined(Q_OS_WIN)
// Install global event filter for processing Windows session related Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION)
qApp->installNativeEventFilter(new WinShutdownMonitor());
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index 3cadac2f2f..7f439fa45e 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -450,6 +450,28 @@ bool ToolTipToRichTextFilter::eventFilter(QObject *obj, QEvent *evt)
return QObject::eventFilter(obj, evt);
}
+LabelOutOfFocusEventFilter::LabelOutOfFocusEventFilter(QObject* parent)
+ : QObject(parent)
+{
+}
+
+bool LabelOutOfFocusEventFilter::eventFilter(QObject* watched, QEvent* event)
+{
+ if (event->type() == QEvent::FocusOut) {
+ auto focus_out = static_cast<QFocusEvent*>(event);
+ if (focus_out->reason() != Qt::PopupFocusReason) {
+ auto label = qobject_cast<QLabel*>(watched);
+ if (label) {
+ auto flags = label->textInteractionFlags();
+ label->setTextInteractionFlags(Qt::NoTextInteraction);
+ label->setTextInteractionFlags(flags);
+ }
+ }
+ }
+
+ return QObject::eventFilter(watched, event);
+}
+
void TableViewLastColumnResizingFixer::connectViewHeadersSignals()
{
connect(tableView->horizontalHeader(), &QHeaderView::sectionResized, this, &TableViewLastColumnResizingFixer::on_sectionResized);
diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h
index 8741d90102..2bd94b5eb3 100644
--- a/src/qt/guiutil.h
+++ b/src/qt/guiutil.h
@@ -162,6 +162,21 @@ namespace GUIUtil
};
/**
+ * Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and
+ * resets their `textInteractionFlags' property to get rid of the visible cursor.
+ *
+ * This is a temporary fix of QTBUG-59514.
+ */
+ class LabelOutOfFocusEventFilter : public QObject
+ {
+ Q_OBJECT
+
+ public:
+ explicit LabelOutOfFocusEventFilter(QObject* parent);
+ bool eventFilter(QObject* watched, QEvent* event) override;
+ };
+
+ /**
* Makes a QTableView last column feel as if it was being resized from its left border.
* Also makes sure the column widths are never larger than the table's viewport.
* In Qt, all columns are resizable from the right, but it's not intuitive resizing the last column from the right.