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. QTextEdit - Table Alignment Impression
Forum Updated to NodeBB v4.3 + New Features

QTextEdit - Table Alignment Impression

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 3.3k 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.
  • Q Offline
    Q Offline
    Quentique
    wrote on last edited by
    #1

    Hello, I want to print a QTextEdit which contains html (a table), the QtextEdit prints but the table isn't correctly align.
    My code :

    @ QTextEdit *test = new QTextEdit;
    test->setStyleSheet(style);
    QString test5 = style + test3.readAll();
    test5.prepend("<center>");
    test5.append("</center>");
    test->append(test5);
    test->show();

    test->print(printer);@
    

    This code works great, when I show the QTextEdit, the table is correctly align but when it printed the table isn't align correctly :
    !http://img11.hostingpics.net/pics/181122Capture.png(Picture)!

    NB : Excuse me for my English, I'm French

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      There's a misunderstanding here. Setting a style sheet on QTextEdit has no influence on it's content. It's for Qt's widget style sheet system.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Quentique
        wrote on last edited by
        #3

        Ok but even if I delete this line of code, it doesn't work...
        I try to replace :
        @test->setStyleSheet(style);@
        by :
        @test.setStyleSheet("text-align: center;");@
        or :
        @test.setStyleSheet("margin-left: auto; margin-right: auto;")@
        But it doesn't work...

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What doesn't work ?

          If you want to style your html, put the styling inside the html. Also take a look at the "Using HTML Markup in Text Widgets" chapter of Qt's documentation

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            Quentique
            wrote on last edited by
            #5

            Look at my first picture, you see that the table isn't correctly align (it's the result of the impression) but if I show the QTextEdit, the table is correctly align :
            !http://img4.hostingpics.net/pics/317411Capture.png(QTextEdit)!

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Can you provide a minimal example that reproduce the behavior ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                Quentique
                wrote on last edited by
                #7

                This is the QTextEdit :
                !http://img4.hostingpics.net/pics/317411Capture.png(QTextEdit)!
                And this is the impression of the QTextEdit :
                !http://img11.hostingpics.net/pics/181122Capture.png(The Impression)!
                So I want that the table be correctly align

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #8

                  The question was:

                  can you provide a simple source code example to show that, so people can play with it :-)

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0
                  • Q Offline
                    Q Offline
                    Quentique
                    wrote on last edited by
                    #9

                    This is my code :
                    @ QPrinter *printer = new QPrinter;
                    printer->setPageSize(QPrinter::A4);
                    qDebug() << "After printer";
                    QPrintDialog *dialogue = new QPrintDialog(printer);
                    qDebug() << "After creation printdialog";
                    dialogue->exec();
                    QFile test2(QCoreApplication::applicationDirPath() + "/style.css");
                    qDebug() << test2.open(QIODevice::ReadOnly);
                    QString style(test2.readAll());
                    style.append("\n</style>");
                    style.prepend("<style>\n");
                    qDebug() << style;
                    QFile test3(QCoreApplication::applicationDirPath() + "/data/max.html");
                    test3.open(QIODevice::ReadOnly);
                    QTextEdit *test = new QTextEdit;
                    test->setStyleSheet(style);
                    QString test5 = style + test3.readAll();
                    test5.prepend("<center>");
                    test5.append("</center>");
                    test->append(test5);
                    test->show();

                      test->print(printer);
                    

                    @
                    This is my HTML code :
                    @<!DOCTYPE html>
                    <html>
                    <head>
                    <meta charset="utf-8" http-equiv="Content-Type" content="text/html"/>
                    <link rel="stylesheet" content="text/css" href="..\\style.css"/>
                    </head>
                    <body>
                    <h1>Max</h1>
                    <h2 id="0"></h2>
                    <div>Langue : Fdfs</div>
                    <table>
                    <thead>
                    <tr>
                    <th>Termes</th>
                    <th>Traductions</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                    <td>fsqd</td>
                    <td>fqd</td>
                    </tr><tr>
                    <td>fsdqf</td>
                    <td>sdqf</td>
                    </tr><tr>
                    <td>g</td>
                    <td> </td>
                    </tr>
                    <tr>
                    <td>g</td>
                    <td> </td>
                    </tr>
                    </tbody>
                    </table>
                    </body>
                    </html>@

                    And my CSS code :
                    @h1
                    {
                    font-size: 20;
                    font-family: Arial;
                    font-weight: false;
                    font-italic: false;
                    color: rgba(255, 0, 0, 255);
                    text-align: center;
                    }
                    h2
                    {
                    font-size: 15;
                    font-family: Arial;
                    font-weight: false;
                    font-italic: false;
                    color: rgba(0, 0, 0, 255);
                    text-align: center;
                    }
                    div
                    {
                    font-size: 12;
                    font-family: Arial;
                    font-weight: false;
                    font-italic: false;
                    color: rgba(0, 128, 0, 255);
                    text-align: center;
                    margin-bottom: 1em;
                    }
                    th
                    {
                    font-size: 12;
                    font-family: Arial;
                    font-weight: false;
                    font-italic: false;
                    color: rgba(0, 0, 255, 255);
                    }
                    tbody tr td:first-child
                    {
                    font-size: 10;
                    font-family: Arial;
                    font-weight: false;
                    font-italic: false;
                    color: rgba(255, 165, 0, 255);
                    text-align: right;
                    }
                    tbody tr td:last-child
                    {
                    font-size: 10;
                    font-family: Arial;
                    font-weight: false;
                    font-italic: false;
                    color: rgba(255, 255, 0, 255);
                    }
                    td, th
                    {
                    border: solid 1px blue;
                    }
                    table
                    {
                    margin-left: auto;
                    margin-right: auto;
                    border-collapse: collapse;
                    }@

                    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 Extensions
                    • Unsolved