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.
  • ManiRonM Offline
    ManiRonM Offline
    ManiRon
    wrote on 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");
            
        }
    
    jsulmJ 1 Reply Last reply
    0
    • ManiRonM 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");
              
          }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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

      ManiRonM 1 Reply Last reply
      1
      • jsulmJ jsulm

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

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

        @jsulm

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

        jsulmJ 1 Reply Last reply
        0
        • ManiRonM ManiRon

          @jsulm

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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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

          ManiRonM 1 Reply Last reply
          1
          • jsulmJ jsulm

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

            ManiRonM Offline
            ManiRonM Offline
            ManiRon
            wrote on 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

            jsulmJ 1 Reply Last reply
            0
            • ManiRonM ManiRon

              @jsulm

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

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on 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

              ManiRonM 1 Reply Last reply
              1
              • jsulmJ jsulm

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

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

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

                JonBJ 1 Reply Last reply
                0
                • ManiRonM ManiRon

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

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on 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

                  • Login

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