Details
-
Bug
-
Resolution: Unresolved
-
P4: Low
-
4.7.1, 5.5.0
-
None
-
Windows
Description
I have a QTextEdit embedded in a QGraphicsScene (via QGraphicsProxyWidget), and view the scene scaled at less than 100% through a QGraphicsView widget.
The cursor frequently doesn't appear, because the 1-pixel width gets scaled down and rounded to zero pixels during drawing.
Looking at QTextLayout::drawCursor, I see there is already code designed to switch on anti-aliasing when drawing a cursor with a painter that has a scaling transformation applied:
bool toggleAntialiasing = !(p->renderHints() & QPainter::Antialiasing)
&& (p->transform().type() > QTransform::TxTranslate)
In this case however, the painter does not have a transform, because this transform has already been applied to the underlying QPaintEngine when the QGraphicsView widget was drawn. The QTextEdit paint method creates a new QPainter which knows nothing about this.
My current workaround is to modify the above line to this:
bool toggleAntialiasing = !(p->renderHints() & QPainter::Antialiasing)
&& (p->transform().type() > QTransform::TxTranslate || p->deviceTransform().type() > QTransform::TxTranslate);
which is fine in my case because I don't use any other QTextEdits elsewhere. I'm not sure if this is necessarily the correct fix, however.
I've attached a small example app that demonstrates this problem. This text edit is scaled to 25%. Try moving the cursor around the text edit. For me the cursor appears in one position, between 'l' and 'i', but not anywhere else.