QtCS25 - Rich Text editing in Qt Quick
Session Summary
Discussion of some past work, work in progress and ideas
Session Owners
Shawn Rutledge
Notes
TextDocument
Existed in Qt 5 (mostly unchanged through 6.6) only to expose TextEdit's document to C++.
A while back we added some QML-facing features:
TextDocument.source = "mydoc.md" TextDocument.save() TextDocument.saveAs("export.html")
But maybe such ad-hoc convenience APIs for I/O are dangerous? Should we go for a standard JS I/O API instead? Nobody expressed being worried, but Andy mentioned https://git.qt.io/annichol/FileAccess
TextSelection
The user can select text, and then we can change things on that single selection:
TextEdit.cursorSelection.alignment TextEdit.cursorSelection.color TextEdit.cursorSelection.font (not a color!) TextEdit.cursorSelection.text
Proposal for 6.10: programmatic editing https://codereview.qt-project.org/c/qt/qtdeclarative/+/523731
- declare (or createObject()) one or more non-vlsual selections as you like
- add some invokables
- linkTo() was what I needed first...
- what else?
Feedback/discussion:
- this is not the same as QTextCursor API. But can it do everything QTextCursor can do?
- maybe call it TextCursor to match C++? (I'm not fond of that idea)
- functionality to test:
- insertion (what if start == end and you set text = "something")
- setting tooltips AKA "alt" text in links
- anyway would Controls tooltips show up for them?
- anchors
- underline style (dashed, wavy etc: known missing so far)
- RTL (probably Igor Khanin will help with that)
- try to create a Qt Quick code editor with syntax highlighting, line numbers, background colors etc.
- this API is not inspired by anything from the JS world. What else is out there?
- CodeMirror
- Monaco
- Scintilla api is also a nice C++ API FWIW.
Other
Other things were on the agenda but we ran out of time.
Igor did a search on sourcegraph.com: found 9 projects where QAbstractTextDocumentLayout was subclassed. But he says there are not good enough docs about how to subclass it.
Improving RTL behavior is one reason to subclass it.
RTL may not work as well in Qt Quick as in widgets (albeit there are corner-case RTL bugs there too)
qtbase/tests/manual/textrendering/codeeditor was a fine example: got removed during the example-vandalism of last year, and now we don't have a code editor that does line numbers. Except for Creator, of course.