stella1016
11th October 2011, 12:52
I am using QTextEdit for this. Method insertHtml() helped. But this method works not as I imagine.
My file1.html is
<html>
<body>
<p>
<h2>title1</h2>
<ul>
<li>bla</li>
<li>bla</li>
</ul>
</p>
<br>
</body>
</html>
File2.html is
<html>
<body>
<p>
<h2>title2</h2>
<ul>
<li>blabla</li>
<li>blabla</li>
</ul>
</p>
<br>
</body>
</html>
My code is:
QString fileName1(":/file1.html");
QFile file1(fileName1);
if (file1.open(QIODevice::ReadOnly))
{
QString data1(file1.readAll());
if (fileName1.endsWith(".html"))
textEdit->insertHtml(data1);
}
QString fileName2(":/file2.html");
QFile file2(fileName2);
if (file2.open(QIODevice::ReadOnly))
{
QString data2(file2.readAll());
if (fileName2.endsWith(".html"))
textEdit->insertHtml(data2);
}
The problem is, the title of the file2 is always followed by the last bla, not aligned to the left of the file. If I insert a break line between these two parts:
textEdit->insertHtml("<hr>");
The line is beneath the file2's title. crazy!
Anyone can help? Or is there another way to complish this function?
Thanks.
My file1.html is
<html>
<body>
<p>
<h2>title1</h2>
<ul>
<li>bla</li>
<li>bla</li>
</ul>
</p>
<br>
</body>
</html>
File2.html is
<html>
<body>
<p>
<h2>title2</h2>
<ul>
<li>blabla</li>
<li>blabla</li>
</ul>
</p>
<br>
</body>
</html>
My code is:
QString fileName1(":/file1.html");
QFile file1(fileName1);
if (file1.open(QIODevice::ReadOnly))
{
QString data1(file1.readAll());
if (fileName1.endsWith(".html"))
textEdit->insertHtml(data1);
}
QString fileName2(":/file2.html");
QFile file2(fileName2);
if (file2.open(QIODevice::ReadOnly))
{
QString data2(file2.readAll());
if (fileName2.endsWith(".html"))
textEdit->insertHtml(data2);
}
The problem is, the title of the file2 is always followed by the last bla, not aligned to the left of the file. If I insert a break line between these two parts:
textEdit->insertHtml("<hr>");
The line is beneath the file2's title. crazy!
Anyone can help? Or is there another way to complish this function?
Thanks.