1 Attachment(s)
Image renders using setHtml method in QTextBrowser but not in QTextEdit
Hi all,
I'm getting inconsistent results with a very short piece of test code in which html text & a small png file renders in a QTextBrowser but not in a QTextEdit. I've tried to boil the issue down to the minimum inAttachment 5669 a test application which behaves as follows:
- when compiled to use a QTextBrowser I get an image (barrel.png) followed by the text fragment "After."
- when compiled to use a QTextEdit I get an image placehoder followed by the text fragment.
If I deliberately supply either version with a non-existent image I get the QTextEdit behaviour (placeholder).
The real life application would have a user drag and drop images onto the chosen widget and display along with notes edited in or dropped from text files.
My reading of the docs has QTextBrowser as an enhanced QTextEdit, with most of the additions being aimed at hyperlinks & navigation. A simple rendering task ought to be common to both?
Here is the code arranged in separate code blocks to reflect what's on my machine :
Header first
Code:
#ifndef TESTDIALOG_H
#define TESTDIALOG_H
#include <QWidget>
// comment this out to switch between options with text edit/browser
//
#define TEXTEDIT
{
Q_OBJECT
public:
explicit TestDialog
(QWidget *parent
= 0);
void test1();
signals:
public slots:
private:
#ifdef TEXTEDIT
#else
#endif
};
#endif // TESTDIALOG_H
Implementation
Code:
#include "testdialog.h"
#include <QtGui/QTextBrowser>
#include <QtGui/QVBoxLayout>
#include <QtGui/QTextFrame>
#include <QtCore/QtDebug>
TestDialog
::TestDialog(QWidget *parent
) :{
#ifdef TEXTEDIT
qDebug() << "With QTextEdit";
#else
qDebug() << "With QTextBrowser";
#endif
layout->addWidget(editor);
this->setLayout(layout);
}
void TestDialog::test1()
{
html += "<body>";
html += "<p>";
html += "<img src = \"file:barrel.png\">";
html += "<p><i>After</i>";
html += "</body>";
editor->setHtml(html);
}
main
Code:
#include <QtGui/QApplication>
#include "testdialog.h"
int main(int argc, char * argv[])
{
TestDialog * td = new TestDialog;
td->show();
td->test1();
return app.exec();
}
I've had the same behaviour on Linux & Mac using Qt 4.7.0 & 4.6.3.
Can anyone see a problem with my code?
Do others get the same result?
Appreciate any pointers - I'm getting nowhere with my attempts to follow using source & debug at the moment. Zip file contains image and qmake pro file along with source quoted above.
Regards,
Amit