0

I would like to add selection handles to a QTextEdit widget so that after the user selects text he or she can expand or shrink the selection in either direction. I understand support for this functionality has been formally added to Qt, but I only see Android mentioned. Is it available for desktop? Is it accessible from PySide? I'm guessing it is too recent for PySide to have the appropriate wrapper.

If selection handles are not formally available, I can imagine how to override the keyPressEvent so that CTRL-click expands or shrinks the current selection by jumping to the cursor's location. However, instead, I would prefer to have a visual cue that can be selected and dragged with a regular mouse-click. Are there graphical widgets that can be painted on top of a QTextEdit window and modified to behave like selection handles?

davideps
  • 541
  • 3
  • 13
  • Are you using qml or the qwidgets? – eyllanesc Oct 15 '17 at 19:23
  • The nearest equivalent would be [QRubberBand](https://doc.qt.io/qt-4.8/qrubberband.html). – ekhumoro Oct 15 '17 at 19:48
  • 1
    Note that the selection can already be extended (from the current caret position) with shift+click. So all you really need is a way to move the caret from one end of the selection to the other (so it can be extended in both directions). There's also ctrl+shift+right/left to select the next/previous word, and shift+home/end to select the start/end of the line. – ekhumoro Oct 15 '17 at 20:10
  • @eyllanesc, I'm using qwidgets. – davideps Oct 15 '17 at 21:24
  • @ekhumoro, thank you. I was unaware of the shift+click functionality. I see what you mean about currently only being able to extend the selection in one direction. Is "the caret" a formal object or just the name of the place where the selection was initially anchored? I will look at the QRubberBand too. – davideps Oct 15 '17 at 21:26
  • 1
    @davideps. The caret is the blinking vertical line that is used to indicate the current insertion point. If you select downwards, it will be at the bottom of the selection; select upwards and it will be at the top. The selection anchor is at the opposite end to the caret (so it's where the selection started from). I suppose you could just change the existing shift+click behaviour so it extended from both ends. That would seem to be the most user-friendly solution. In fact, I don't know why that isn't the default behaviour, since it seems the most useful (and intuitive). – ekhumoro Oct 15 '17 at 22:22

0 Answers0