Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-16610

When a QTextEdit embedded in a QGraphicsScene is viewed through a scaled QGraphicsView, the cursor is not antialiased

    XMLWordPrintable

Details

    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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            jlarcombe James Larcombe
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes