Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Unsolved How to align a table created using HTML to center

    General and Desktop
    3
    8
    772
    Loading More Posts
    • 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.
    • ManiRon
      ManiRon last edited by ManiRon

      I am trying to create a table that can be printed in a html format file . and its printing but the only concern is that its printing to the left of file and i want it at the center of file . What code should be added to make it print at the center of the page?
      Below is the code which i have used to print the table

      css1 = "<style type="text/css">";
      css1 += "table.tbl {border-width: 1px;border-style: solid;border-color: black;margin-top: 0px;margin-bottom: 0px;color: black;}";
      css1 += "table.tbl td {padding: 3px;}";
      css1 += "table.tbl th {padding: 3px;font-size: 18px;}";
      css1+="</style>";

               text1 = "<table width=\"50%\"  cellspacing=\"0\" class=\"tbl\">";
               text1 +=("<tr><td>"+qfont+"</td><td>" + name) +"</td>");
               text1 +=("<tr><td>"+qTestedBy+"</td><td>" +TestedBy+"</td>");
               text1 +=("<tr><td>"+qCurrentDate+"</td><td>" + QDate::currentDate().toString() +"</td>");
               text1 +=("<tr><td>"+qCurrentTime+"</td><td>" + QTime::currentTime().toString() +"</td>");
      

      QFile qHtmlFile(qFileName);
      if (qHtmlFile.exists())
      {
      if(qHtmlFile.open(QIODevice::ReadWrite))
      {
      QTextStream qData(&qHtmlFile);
      qRep = qIndex+qAll+css+text
      qTextRep.document()->setHtml(qRep);
      qTextRep.setFont(qFon);
      qData << qTextRep.document()->toHtml();

                    qDebug("Report Created");
              
          }
      
      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @ManiRon last edited by

        @ManiRon said in How to align a table created using HTML to center:

        its printing to the left of file and i want it at the center of file

        I don't understand: do you mean it is left aligned when viewing the HTML file in a web browser?
        And what exactly is left aligned: the content of the cells or the table itself?

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

        ManiRon 1 Reply Last reply Reply Quote 1
        • ManiRon
          ManiRon @jsulm last edited by

          @jsulm

          the table itself and i want to align it to the center of the page

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @ManiRon last edited by

            @ManiRon So, in the web browser? In this case I don't see how it is related to Qt, you need to find out how to center a table in HTML.
            What you posted doesn't even look like HTML (where is <html></html>?).

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

            ManiRon 1 Reply Last reply Reply Quote 1
            • ManiRon
              ManiRon @jsulm last edited by ManiRon

              @jsulm

              I am just using the HTML format to create so i store the things in QString variable and print it

              jsulm 1 Reply Last reply Reply Quote 0
              • jsulm
                jsulm Lifetime Qt Champion @ManiRon last edited by

                @ManiRon As I said, your problem is more related to HTML not Qt. I'm not an HTML expert, so don't know how to center a table. Maybe https://www.w3schools.com/tags/att_table_align.asp ?

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

                ManiRon 1 Reply Last reply Reply Quote 1
                • ManiRon
                  ManiRon @jsulm last edited by

                  @jsulm I saw that and tried it but its not center align the table

                  JonB 1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB @ManiRon last edited by

                    @ManiRon
                    To align table centrally horizontally, use one of the following:

                    • <table style="margin-left: auto; margin-right: auto;">
                    • <table style="margin-left: 0; margin-right: auto;">
                    • Put table inside <div></div> and align that.

                    The above may assume you have something like html, body { width: 100%; } so that it knows what to center within, I'm not sure, you might have to play.

                    1 Reply Last reply Reply Quote 2
                    • First post
                      Last post