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 inreport.zip 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

Qt Code:
  1. #ifndef TESTDIALOG_H
  2. #define TESTDIALOG_H
  3.  
  4. #include <QWidget>
  5.  
  6. class QTextEdit;
  7.  
  8.  
  9. // comment this out to switch between options with text edit/browser
  10. //
  11. #define TEXTEDIT
  12.  
  13. class TestDialog : public QWidget
  14. {
  15. Q_OBJECT
  16. public:
  17. explicit TestDialog(QWidget *parent = 0);
  18.  
  19. void test1();
  20.  
  21.  
  22. signals:
  23.  
  24. public slots:
  25.  
  26. private:
  27.  
  28. #ifdef TEXTEDIT
  29. QTextEdit *editor;
  30. #else
  31. QTextBrowser *editor;
  32. #endif
  33.  
  34. };
  35.  
  36. #endif // TESTDIALOG_H
To copy to clipboard, switch view to plain text mode 


Implementation


Qt Code:
  1. #include "testdialog.h"
  2.  
  3. #include <QtGui/QTextBrowser>
  4. #include <QtGui/QVBoxLayout>
  5. #include <QtGui/QTextFrame>
  6.  
  7. #include <QtCore/QtDebug>
  8.  
  9.  
  10. TestDialog::TestDialog(QWidget *parent) :
  11. QWidget(parent)
  12. {
  13.  
  14. #ifdef TEXTEDIT
  15. editor = new QTextEdit(this);
  16. qDebug() << "With QTextEdit";
  17. #else
  18. editor = new QTextBrowser(this);
  19. qDebug() << "With QTextBrowser";
  20. #endif
  21.  
  22. QVBoxLayout *layout = new QVBoxLayout;
  23. layout->addWidget(editor);
  24. this->setLayout(layout);
  25.  
  26. }
  27.  
  28.  
  29.  
  30. void TestDialog::test1()
  31. {
  32.  
  33. QString html;
  34. html += "<body>";
  35. html += "<p>";
  36. html += "<img src = \"file:barrel.png\">";
  37. html += "<p><i>After</i>";
  38. html += "</body>";
  39.  
  40. editor->setHtml(html);
  41.  
  42. }
To copy to clipboard, switch view to plain text mode 

main

Qt Code:
  1. #include <QtGui/QApplication>
  2.  
  3.  
  4. #include "testdialog.h"
  5.  
  6.  
  7.  
  8. int main(int argc, char * argv[])
  9. {
  10.  
  11. QApplication app(argc, argv);
  12.  
  13. TestDialog * td = new TestDialog;
  14. td->show();
  15. td->test1();
  16.  
  17.  
  18. return app.exec();
  19. }
To copy to clipboard, switch view to plain text mode 

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