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. how to give the html tag line to QString
Qt 6.11 is out! See what's new in the release blog

how to give the html tag line to QString

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 5 Posters 3.2k 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.
  • aha_1980A aha_1980

    @ManiRon

    Yeah, because your example

    QString qPrint = "("<button type="button">Click Me!</button>")";

    is different from your first example and different from mine. Just use the version in my post above.

    ManiRonM Offline
    ManiRonM Offline
    ManiRon
    wrote on last edited by
    #5

    @aha_1980
    error: expected ',' or ';' before 'button'
    QString qPrint = "<button type="button">Click Me!</button>";
    ^

    Again error

    aha_1980A 1 Reply Last reply
    0
    • ManiRonM ManiRon

      @aha_1980
      error: expected ',' or ';' before 'button'
      QString qPrint = "<button type="button">Click Me!</button>";
      ^

      Again error

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @ManiRon Ah, sorry. You need to escape the inner quotation marks. I've edited my post above.

      Qt has to stay free or it will die.

      ManiRonM 1 Reply Last reply
      0
      • aha_1980A aha_1980

        @ManiRon Ah, sorry. You need to escape the inner quotation marks. I've edited my post above.

        ManiRonM Offline
        ManiRonM Offline
        ManiRon
        wrote on last edited by
        #7

        @aha_1980

        Ya i tried with the edited code but it is not creating the button and it just displays the text click me in the html file

        1 Reply Last reply
        0
        • aha_1980A aha_1980

          @ManiRon

          but it is throwing error

          Which error is thrown by whom?

          QString qHtml = "<button type=\"button\">Click Me!</button>"; should at least compile fine.

          ManiRonM Offline
          ManiRonM Offline
          ManiRon
          wrote on last edited by
          #8

          @aha_1980 this just prints the click me in the html file

          cfdevC 1 Reply Last reply
          0
          • ManiRonM ManiRon

            @aha_1980 this just prints the click me in the html file

            cfdevC Offline
            cfdevC Offline
            cfdev
            wrote on last edited by
            #9

            @ManiRon maybe you must assign a stylesheet ? how do you renderer it ?

            ManiRonM 1 Reply Last reply
            0
            • cfdevC cfdev

              @ManiRon maybe you must assign a stylesheet ? how do you renderer it ?

              ManiRonM Offline
              ManiRonM Offline
              ManiRon
              wrote on last edited by
              #10

              @cfdev i am not getting you

              cfdevC 1 Reply Last reply
              0
              • ManiRonM ManiRon

                @cfdev i am not getting you

                cfdevC Offline
                cfdevC Offline
                cfdev
                wrote on last edited by
                #11

                @ManiRon what is your html engine ?
                your application with qtextdocument or QtWebEngine or other ?

                ManiRonM 1 Reply Last reply
                0
                • cfdevC cfdev

                  @ManiRon what is your html engine ?
                  your application with qtextdocument or QtWebEngine or other ?

                  ManiRonM Offline
                  ManiRonM Offline
                  ManiRon
                  wrote on last edited by ManiRon
                  #12

                  @cfdev QTextBrowser and QTextStream

                  QTextBrowser qTextRep;
                  QTextStream qData(&qHtmlFile);
                  qTextRep.document()->setHtml(qHtml);

                      qData << qTextRep.document()->toHtml();
                  
                  cfdevC JonBJ 2 Replies Last reply
                  0
                  • ManiRonM ManiRon

                    @cfdev QTextBrowser and QTextStream

                    QTextBrowser qTextRep;
                    QTextStream qData(&qHtmlFile);
                    qTextRep.document()->setHtml(qHtml);

                        qData << qTextRep.document()->toHtml();
                    
                    cfdevC Offline
                    cfdevC Offline
                    cfdev
                    wrote on last edited by
                    #13

                    @ManiRon said in how to give the html tag line to QString:

                    QTextBrowser

                    Ok, see https://doc.qt.io/qt-5/richtext-html-subset.html, because last attributs of html are not supported like "<button>".

                    1 Reply Last reply
                    3
                    • ManiRonM ManiRon

                      @cfdev QTextBrowser and QTextStream

                      QTextBrowser qTextRep;
                      QTextStream qData(&qHtmlFile);
                      qTextRep.document()->setHtml(qHtml);

                          qData << qTextRep.document()->toHtml();
                      
                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #14

                      @ManiRon
                      If I understand @cfdev's reference right, you will not be able to put a <button> tag (or for that matter an <input type="button">) on a QTextBrowser. I could be wrong(!), but I think it allows browsing only, it does not support adding "interaction" tags. It does support <a href=...>, though presumably for a URL only not JavaScript, if that might give what you want.

                      I have no idea what you're trying to achieve, but if it exceeds what QTextBrowser can do are you at least aware of https://doc.qt.io/qt-5/qwebengineview.html ? That is a Chromium-browser-widget, much more "heavyweight" than QTextBrowser but might be what you are looking for?

                      ManiRonM 1 Reply Last reply
                      1
                      • JonBJ JonB

                        @ManiRon
                        If I understand @cfdev's reference right, you will not be able to put a <button> tag (or for that matter an <input type="button">) on a QTextBrowser. I could be wrong(!), but I think it allows browsing only, it does not support adding "interaction" tags. It does support <a href=...>, though presumably for a URL only not JavaScript, if that might give what you want.

                        I have no idea what you're trying to achieve, but if it exceeds what QTextBrowser can do are you at least aware of https://doc.qt.io/qt-5/qwebengineview.html ? That is a Chromium-browser-widget, much more "heavyweight" than QTextBrowser but might be what you are looking for?

                        ManiRonM Offline
                        ManiRonM Offline
                        ManiRon
                        wrote on last edited by ManiRon
                        #15

                        @JonB

                        Actually i am trying to create a button to make the html report to be printed to a pdf . by giving the window.print() call

                        JonBJ 1 Reply Last reply
                        0
                        • ManiRonM ManiRon

                          @JonB

                          Actually i am trying to create a button to make the html report to be printed to a pdf . by giving the window.print() call

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #16

                          @ManiRon
                          Again, I could be wrong :), but that is JavaScript and I don't think QTextBrowser is going to allow that. window.print() is JavaScript and I don't think that's going to work. Try something like:

                          <a href="window.print()">Print me</a>
                          <a href="javascript:window.print()">Print me</a>
                          

                          and see what happens (probably nothing).

                          You might instead have your code pull the HTML back from the QTextBrowser and do it yourself. Or, the QWebEngine I told you about will (should) allow window.print(); alternatively, as I do in my code, it allows you to handle printing yourself via e.g. https://doc.qt.io/qt-5/qwebenginepage.html#printToPdf. You can force using PDF either to the printer directly, or to a file, and you can also print directly to printer without going via PDF.

                          ManiRonM 1 Reply Last reply
                          4
                          • JonBJ JonB

                            @ManiRon
                            Again, I could be wrong :), but that is JavaScript and I don't think QTextBrowser is going to allow that. window.print() is JavaScript and I don't think that's going to work. Try something like:

                            <a href="window.print()">Print me</a>
                            <a href="javascript:window.print()">Print me</a>
                            

                            and see what happens (probably nothing).

                            You might instead have your code pull the HTML back from the QTextBrowser and do it yourself. Or, the QWebEngine I told you about will (should) allow window.print(); alternatively, as I do in my code, it allows you to handle printing yourself via e.g. https://doc.qt.io/qt-5/qwebenginepage.html#printToPdf. You can force using PDF either to the printer directly, or to a file, and you can also print directly to printer without going via PDF.

                            ManiRonM Offline
                            ManiRonM Offline
                            ManiRon
                            wrote on last edited by
                            #17

                            @JonB said in how to give the html tag line to QString:

                            "javascript:window.print()

                            I tried both and this one (<a href="javascript:window.print()">Print me</a>) worked and asked for which printer to use and i select one suddenly it says some error has occured

                            mrjjM 1 Reply Last reply
                            0
                            • ManiRonM ManiRon

                              @JonB said in how to give the html tag line to QString:

                              "javascript:window.print()

                              I tried both and this one (<a href="javascript:window.print()">Print me</a>) worked and asked for which printer to use and i select one suddenly it says some error has occured

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #18

                              @ManiRon said in how to give the html tag line to QString:

                              some error has occured

                              So if you need any input to that, the actual error would be helpful ! :)

                              1 Reply Last reply
                              2

                              • Login

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