Details
-
Bug
-
Resolution: Duplicate
-
P1: Critical
-
None
-
6.5.3, 6.6.1
-
None
Description
In Qt 6, <img src="file:///..."> the file URL is magled by QTextDocument when trying to load the resource. The URL passed to loadResource() is the original URL with the leading file:/ stripped. QUrl.isRelative() returns True for such URLs causing loadResource() to fail on Windows. On Unix it still works, because the leading double slash is equivalent to a leading single slash. On Windows, file:///C:/some/path becomes //c/some/path which fails to load.
A trivial PyQt6 script to reproduce the issue:
import os from PyQt6.QtCore import QUrl from PyQt6.QtGui import QTextDocument, QPainter, QImage from PyQt6.QtWidgets import QApplication class D(QTextDocument): def loadResource(self, rtype, qurl): print('actual URL:', qurl) ans = super().loadResource(rtype, qurl) if not ans: raise Exception(f'Failed to load: {qurl}') return ans app = QApplication([]) d = D() url = QUrl.fromLocalFile(os.path.abspath(__file__)).toString() d.setHtml(f'<p><img src="{url}">') print('expected url:', url) img = QImage(100, 100, QImage.Format.Format_ARGB32_Premultiplied) p = QPainter(img) d.drawContents(p) del d del app
Running this script produces no errors on Unic like OSes. On Windows it fails with the Exception Failed to load URL, because QTextDocument::loadResource() fails for the mangled URL passed to it.
This bug breaks using images with file:// URLs in all widgets that use QTextDocument which include, QTextEdit, QToolTip, QTextBrowser, etc. etc. It is not present Qt 5.
Attachments
Issue Links
- duplicates
-
QTBUG-120577 qt6.5.3 QTextEdit can't display image ! but qt5.15 is ok 。
-
- Closed
-