Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.7.2
-
None
-
c7df8dda8 (dev), 051764ddf (6.8)
Description
When calling QPainter::drawText(QRectF, QString) with an invalid rect, e.g.
painter->drawText(QRectF(), "foo")
then nothing will be drawn unless the painter is rendering to a QSvgGenerator, in which case the text will be displayed at (0, 0). Here's a PySide6 script that demonstrates the issue, but we've experienced this with C++ code as well:
from PySide6 import QtWidgets, QtGui, QtCore, QtSvg from PySide6.QtCore import Qt app = QtWidgets.QApplication([]) widget = QtWidgets.QWidget() layout = QtWidgets.QHBoxLayout(widget) widget.setLayout(layout) for test in ['invalid_SVG', 'valid_SVG', 'invalid_PXM', 'valid_PXM']: if 'invalid' in test: rect = QtCore.QRectF() # invalid rect else: rect = QtCore.QRectF(25, 25, 75, 75) # valid rect pixmap = QtGui.QPixmap(100, 100) painter = QtGui.QPainter() if 'SVG' in test: svg_gen = QtSvg.QSvgGenerator() buffer = QtCore.QBuffer() svg_gen.setOutputDevice(buffer) svg_gen.setSize(QtCore.QSize(100, 100)) painter.begin(svg_gen) else: painter.begin(pixmap) painter.fillRect(QtCore.QRect(0, 0, 100, 100), Qt.white) painter.setPen(Qt.black) painter.drawText(rect, test) painter.end() if 'SVG' in test: pixmap.loadFromData(buffer.data(), "SVG") label = QtWidgets.QLabel(widget) layout.addWidget(label) label.setPixmap(pixmap) widget.show() app.exec()
This script generates
As you can see, "invalid_SVG" is rendered to the upper-left corner of the first image, but nothing is rendered to the third image (where the text is rendered to an invalid QRectF in a pixmap).