diff --git a/src/view/urllabel.cpp b/src/view/urllabel.cpp index 80851ba81..73860215d 100644 --- a/src/view/urllabel.cpp +++ b/src/view/urllabel.cpp @@ -1,49 +1,51 @@ /* view/urllabel.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2021, 2022 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "urllabel.h" #include using namespace Kleo; UrlLabel::UrlLabel(QWidget *parent) : HtmlLabel{parent} { } UrlLabel::~UrlLabel() = default; void UrlLabel::setUrl(const QUrl &url, const QString &text) { // we prepend a zero-width-space character to work around a bug in QLabel::focusNextPrevChild(false) // which makes it impossible to leave the label with Shift+Tab if the text starts with a link static const QString templateString{QLatin1String{"​%2"}}; if (url.isEmpty()) { HtmlLabel::setHtml({}); return; } setHtml(templateString.arg( url.url(QUrl::FullyEncoded), text.isEmpty() ? url.toDisplayString().toHtmlEscaped() : text.toHtmlEscaped())); } void UrlLabel::focusInEvent(QFocusEvent *event) { // immediately focus the URL when the label get focus QLabel::focusInEvent(event); if (!hasSelectedText()) { - focusNextPrevChild(true); + QMetaObject::invokeMethod(this, [this]() { + focusNextPrevChild(true); + }, Qt::QueuedConnection); } }