I think there might be a bug in QTextEdit and .insertHtml and .insertText methods.

Here an example:

Qt Code:
  1. import sys
  2. from PyQt4 import *
  3. from PyQt4 import QtCore
  4. from PyQt4 import QtGui
  5. from PyQt4.QtCore import *
  6. from PyQt4.QtGui import *
  7.  
  8. class Gui(QWidget):
  9. def __init__(self):
  10. QWidget.__init__(self, parent=None)
  11. screen = QDesktopWidget().screenGeometry()
  12. self.resize(screen.width(), screen.height()/2)
  13. self.move((screen.width() - self.geometry().width()) / 2, 0)
  14. self.textArea = QTextEdit(self)
  15. self.cursor = QTextCursor(self.textArea.document())
  16. self.show()
  17. self.cursor.insertHtml("<a href='http://www.w3schools.com/'>Link!</a>")
  18. self.cursor.insertText("something")
  19.  
  20. class Main(QMainWindow):
  21. def __init__(self):
  22. QMainWindow.__init__(self, parent=None)
  23. self.gui = Gui()
  24.  
  25.  
  26.  
  27. app = QtGui.QApplication(sys.argv)
  28. window = Main()
  29. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode 

A normal webbrowser will render "<a href='http://www.w3schools.com/'>Link!</a>something" as "Link!something", but instead of that QTextEdit renders it as "Link!something"

Where is the problem? And how can I prevent QTextEdit acting like that?