vcl/qt5/QtHyperlinkLabel.cxx |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

New commits:
commit eb479763e758c3ac2b886dc90272d03b0a63c5fb
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Nov 8 22:25:17 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Nov 9 19:03:44 2024 +0100

    tdf#130857 qt weld: Always set non-empty link target
    
    In QtHyperlinkLabel::update, always set a non-empty
    string for the link target, as otherwise the text
    in the QLabel will not be a clickable hyperlink, but
    just plain text. While that seems reasonable in general,
    this is problematic as the QtHyperlinkLabel is the widget
    used for QtInstanceLinkButton, and a weld::LinkButton
    should be clickable even if the link target is empty, as
    a custom signal handler can be set that doesn't make use
    of th URI anyway.
    
    Therefore, just set a single space character as the URI
    if the actual one is empty.
    
    This is relevant e.g. for the "LibreOfficeDev Help Not
    Installed" dialog that shows when pressing F1 in a build
    not including local help, which will be declared as
    supported in an upcoming commit.
    
    Change-Id: I1db4c405793109ae9af811d6dd08b1da37246271
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176297
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/qt5/QtHyperlinkLabel.cxx b/vcl/qt5/QtHyperlinkLabel.cxx
index 91851c285ac1..6b961b9355cc 100644
--- a/vcl/qt5/QtHyperlinkLabel.cxx
+++ b/vcl/qt5/QtHyperlinkLabel.cxx
@@ -29,7 +29,10 @@ void QtHyperlinkLabel::setUri(const QString& rUri)
 
 void QtHyperlinkLabel::update()
 {
-    setText(QLatin1String("<a 
href=\"%1\">%2</a>").arg(m_sUri).arg(m_sDisplayText));
+    // Always set a non-empty URI, otherwise there's no clickable hyperlink
+    // (custom slot for QLabel::linkActivated doesn't necessarily need a URI)
+    const QString sUri = !m_sUri.isEmpty() ? m_sUri : QStringLiteral(" ");
+    setText(QLatin1String("<a 
href=\"%1\">%2</a>").arg(sUri).arg(m_sDisplayText));
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to