Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextBrowser hyperlink "spreading" to other text rows
Qt 6.12 LTS is out! See what's new in the release blog

QTextBrowser hyperlink "spreading" to other text rows

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 868 Views
  • 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.
  • T Offline
    T Offline
    Tantsa
    wrote on last edited by
    #1

    Hi,

    I am trying to have hyperlink in my QTextBrowser that open file location when it is clicked. It works fine, but there is bug that causes hyperlink to spread other text rows. Other rows are valid hyperlinks to actual links filepath. spreading hyperlink.png QTextBrowser looks like that. Those <CollectMission> lines are not supposed to be hyperlinks.

    Hyperlink is written using function:

    void MainWindow::WriteHyperLink(QStringList text, QString URL ){
        QString hyperLink = QString("<a href=%1>%2</a>%3").arg(URL, text.at(0), text.at(1));
        ui->textBrowser->append(hyperLink);
    }
    

    where text.at(0) is path to folder and text.at(1) is filename (int this case "/annotation_test_with_grip_pose_estimation.json")

    Text is written using following function:

    void MainWindow::WriteText(QString message, QString parentName)
    {
        QString textToWrite;
        if (parentName != ""){
            textToWrite = QStringLiteral("<%1> %2").arg(parentName, message);
        } else {
            textToWrite = str;
        }
        ui->textBrowser->append(textToWrite);
    
    }
    

    Any ideas how to fix this?

    jsulmJ 2 Replies Last reply
    0
    • T Tantsa

      Hi,

      I am trying to have hyperlink in my QTextBrowser that open file location when it is clicked. It works fine, but there is bug that causes hyperlink to spread other text rows. Other rows are valid hyperlinks to actual links filepath. spreading hyperlink.png QTextBrowser looks like that. Those <CollectMission> lines are not supposed to be hyperlinks.

      Hyperlink is written using function:

      void MainWindow::WriteHyperLink(QStringList text, QString URL ){
          QString hyperLink = QString("<a href=%1>%2</a>%3").arg(URL, text.at(0), text.at(1));
          ui->textBrowser->append(hyperLink);
      }
      

      where text.at(0) is path to folder and text.at(1) is filename (int this case "/annotation_test_with_grip_pose_estimation.json")

      Text is written using following function:

      void MainWindow::WriteText(QString message, QString parentName)
      {
          QString textToWrite;
          if (parentName != ""){
              textToWrite = QStringLiteral("<%1> %2").arg(parentName, message);
          } else {
              textToWrite = str;
          }
          ui->textBrowser->append(textToWrite);
      
      }
      

      Any ideas how to fix this?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @Tantsa said in QTextBrowser hyperlink "spreading" to other text rows:

      "<a href=%1>%2</a>%3"

      Shouldn't it be

      "<a href=\"%1\">%2</a>%3"
      

      ?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply
      2
      • T Tantsa

        Hi,

        I am trying to have hyperlink in my QTextBrowser that open file location when it is clicked. It works fine, but there is bug that causes hyperlink to spread other text rows. Other rows are valid hyperlinks to actual links filepath. spreading hyperlink.png QTextBrowser looks like that. Those <CollectMission> lines are not supposed to be hyperlinks.

        Hyperlink is written using function:

        void MainWindow::WriteHyperLink(QStringList text, QString URL ){
            QString hyperLink = QString("<a href=%1>%2</a>%3").arg(URL, text.at(0), text.at(1));
            ui->textBrowser->append(hyperLink);
        }
        

        where text.at(0) is path to folder and text.at(1) is filename (int this case "/annotation_test_with_grip_pose_estimation.json")

        Text is written using following function:

        void MainWindow::WriteText(QString message, QString parentName)
        {
            QString textToWrite;
            if (parentName != ""){
                textToWrite = QStringLiteral("<%1> %2").arg(parentName, message);
            } else {
                textToWrite = str;
            }
            ui->textBrowser->append(textToWrite);
        
        }
        

        Any ideas how to fix this?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @Tantsa I'm not sure I understand your description: do you mean the hyperlink is wraped, so part of it is shown in next line?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tantsa
          wrote on last edited by Tantsa
          #3

          @jsulm
          No, there is one hyperlink added using WriteHyperLink() function and then added normal text using WriteText() function.
          However text written using WriteText() appears as hyperlink too, when it is supposed to be plain text.

          If you take careful look to image hyperlink is only "C:/Users/ [...] /json/annotation_test_with_grip", because that is path to folder that is supposed to open. Filename with extension (.json) is not part of hyperlink.

          Now every new line to added to QTextBrowser becomes to hyperlink that have same location as original hyperlink, but different text.

          1 Reply Last reply
          0
          • T Tantsa

            Hi,

            I am trying to have hyperlink in my QTextBrowser that open file location when it is clicked. It works fine, but there is bug that causes hyperlink to spread other text rows. Other rows are valid hyperlinks to actual links filepath. spreading hyperlink.png QTextBrowser looks like that. Those <CollectMission> lines are not supposed to be hyperlinks.

            Hyperlink is written using function:

            void MainWindow::WriteHyperLink(QStringList text, QString URL ){
                QString hyperLink = QString("<a href=%1>%2</a>%3").arg(URL, text.at(0), text.at(1));
                ui->textBrowser->append(hyperLink);
            }
            

            where text.at(0) is path to folder and text.at(1) is filename (int this case "/annotation_test_with_grip_pose_estimation.json")

            Text is written using following function:

            void MainWindow::WriteText(QString message, QString parentName)
            {
                QString textToWrite;
                if (parentName != ""){
                    textToWrite = QStringLiteral("<%1> %2").arg(parentName, message);
                } else {
                    textToWrite = str;
                }
                ui->textBrowser->append(textToWrite);
            
            }
            

            Any ideas how to fix this?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @Tantsa said in QTextBrowser hyperlink "spreading" to other text rows:

            "<a href=%1>%2</a>%3"

            Shouldn't it be

            "<a href=\"%1\">%2</a>%3"
            

            ?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            T 1 Reply Last reply
            2
            • jsulmJ jsulm

              @Tantsa said in QTextBrowser hyperlink "spreading" to other text rows:

              "<a href=%1>%2</a>%3"

              Shouldn't it be

              "<a href=\"%1\">%2</a>%3"
              

              ?

              T Offline
              T Offline
              Tantsa
              wrote on last edited by
              #5

              @jsulm said in QTextBrowser hyperlink "spreading" to other text rows:

              @Tantsa said in QTextBrowser hyperlink "spreading" to other text rows:

              "<a href=%1>%2</a>%3"

              Shouldn't it be

              "<a href=\"%1\">%2</a>%3"
              

              ?

              Thank you, this solved problem.

              1 Reply Last reply
              0

              • Login

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