QTextEdit - Table Alignment Impression
-
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
-
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.
-
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... -
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
-
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)! -
Can you provide a minimal example that reproduce the behavior ?
-
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 -
The question was:
can you provide a simple source code example to show that, so people can play with it :-)
-
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;
}@