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 align a table created using HTML to center

How to align a table created using HTML to center

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 4.0k 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.
  • M Offline
    M Offline
    ManiRon
    wrote on 20 Feb 2019, 05:26 last edited by ManiRon
    #1

    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");
            
        }
    
    J 1 Reply Last reply 20 Feb 2019, 06:03
    0
    • M ManiRon
      20 Feb 2019, 05:26

      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");
              
          }
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 20 Feb 2019, 06:03 last edited by
      #2

      @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

      M 1 Reply Last reply 20 Feb 2019, 06:08
      1
      • J jsulm
        20 Feb 2019, 06:03

        @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?

        M Offline
        M Offline
        ManiRon
        wrote on 20 Feb 2019, 06:08 last edited by
        #3

        @jsulm

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

        J 1 Reply Last reply 20 Feb 2019, 06:12
        0
        • M ManiRon
          20 Feb 2019, 06:08

          @jsulm

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

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 20 Feb 2019, 06:12 last edited by
          #4

          @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

          M 1 Reply Last reply 20 Feb 2019, 06:14
          1
          • J jsulm
            20 Feb 2019, 06:12

            @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>?).

            M Offline
            M Offline
            ManiRon
            wrote on 20 Feb 2019, 06:14 last edited by ManiRon
            #5

            @jsulm

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

            J 1 Reply Last reply 20 Feb 2019, 06:17
            0
            • M ManiRon
              20 Feb 2019, 06:14

              @jsulm

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

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 20 Feb 2019, 06:17 last edited by
              #6

              @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

              M 1 Reply Last reply 20 Feb 2019, 06:33
              1
              • J jsulm
                20 Feb 2019, 06:17

                @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 ?

                M Offline
                M Offline
                ManiRon
                wrote on 20 Feb 2019, 06:33 last edited by
                #7

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

                J 1 Reply Last reply 20 Feb 2019, 10:47
                0
                • M ManiRon
                  20 Feb 2019, 06:33

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

                  J Offline
                  J Offline
                  JonB
                  wrote on 20 Feb 2019, 10:47 last edited by
                  #8

                  @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
                  2

                  3/8

                  20 Feb 2019, 06:08

                  5 unread
                  • Login

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