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

TextInput with cursorDelegate and clipping: custom cursor gets clipped

    XMLWordPrintable

Details

    • 41c35b04d5ebddb4738df984bfdfee2dcd075e64 (qt/qtdeclarative/dev)

    Description

      import QtQuick 2.0
      
      Rectangle {
          width: 200
          height: 40
      
          TextInput {
              cursorDelegate: Rectangle { border.color: "red"; color: "lightsteelblue"; opacity: 0.5; width: 10 }
              anchors.centerIn: parent
              text: "some text"
              width: 0
              clip: true
              focus: true
          }
      }
      

      You'll only see a 1-pixel line, because clipRect() is called too early before the cursorItem gets instantiated, so TextInput pads it by only one pixel:

      QRectF QQuickTextInput::clipRect() const
      {
          Q_D(const QQuickTextInput);
      
          int cursorWidth = d->cursorItem ? d->cursorItem->width() : 1;
          // Could include font max left/right bearings to either side of rectangle.
          QRectF r = QQuickImplicitSizeItem::clipRect();
          r.setRight(r.right() + cursorWidth);
      qDebug() << "cursor" << d->cursorItem << "w" << cursorWidth << "clip would be" << QQuickImplicitSizeItem::clipRect() << "now" << r;;
          return r;
      }
      

      Attachments

        Issue Links

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

          Activity

            People

              srutledg Shawn Rutledge
              srutledg Shawn Rutledge
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes