Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextBrowser::anchorClicked not emitted
Forum Updated to NodeBB v4.3 + New Features

QTextBrowser::anchorClicked not emitted

Scheduled Pinned Locked Moved Solved General and Desktop
qtextbrowser
2 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by VRonin
    #1

    Using a widget inheriting from QTextBrowser, and calling in the constructor:

        setOpenLinks(false);
        setOpenExternalLinks(false);
        setReadOnly(false);
    

    I add a link to a local file to the document this way:

    // destinationPath is QString with the file path, e.g. C:/Temp/afile.dat
        QTextCharFormat fmt;
        fmt.setAnchor(true);
        fmt.setAnchorHref(QUrl::fromLocalFile(destinationPath).toString(QUrl::FullyEncoded));
        fmt.setForeground(QApplication::palette().color(QPalette::Link));
        fmt.setFontUnderline(true);
        QTextCursor cursor = textCursor();
        const QTextCharFormat previousFormat = cursor.charFormat();
        cursor.insertText(origFile.fileName(), fmt);
        cursor.insertText(QStringLiteral(" "), previousFormat);
    

    In the constructor I also do the connection

    connect(this, &QTextBrowser::anchorClicked, this, &MTextEdit::urlActivated);
    

    but the slot is never called.

    I checked the produced html code and it has <a href=...> in it so any idea why the anchor is never activated?

    Thanks in advance

    System:
    Qt 5.6 on Windows with MSVC2013

    Background:
    I'm using in my project a modified version of MRichTextEditor the full code for the class is here: header source (the only thing defined in Globals.h is debugConsole that translates into qDebug() and PBglobals::docsRepository() which translates in

    QString PBglobals::docsRepository()
    {
        return QCoreApplication::applicationDirPath() + "/DocsRepo";
    }
    

    To test it just drop a file in the textedit and try opening it

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Setting read only to false switches interaction flags from Qt::TextBrowserInteraction to Qt::TextEditorInteraction which disables interactive links.
      To enable them back set the Qt::LinksAccessibleByMouse flag:

      setOpenLinks(false);
      setOpenExternalLinks(false);
      setReadOnly(false);
      setTextInteractionFlags(textInteractionFlags() | Qt::LinksAccessibleByMouse);
      
      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved