admin管理员组文章数量:1278880
I am building a code editor in QScintilla and PyQt6. I wanted to create an extra wide CARET (blinking cursor) like in terminal:
When I try modifying the CARET width using the default method
editor = QScintilla()
editor.setCaretWidth(15)
it has a fixed maximum effect, meaning that any number bigger than 12px will not change the width anymore. Is there a way to make the CARET even wider?
I am building a code editor in QScintilla and PyQt6. I wanted to create an extra wide CARET (blinking cursor) like in terminal:
When I try modifying the CARET width using the default method
editor = QScintilla()
editor.setCaretWidth(15)
it has a fixed maximum effect, meaning that any number bigger than 12px will not change the width anymore. Is there a way to make the CARET even wider?
Share Improve this question asked Feb 24 at 2:25 COIsCuriousCOIsCurious 131 silver badge3 bronze badges1 Answer
Reset to default 1Setting the caret width is inappropriate, because that sets the width of the vertical caret, which obviously presents two issues:
- it doesn't consider the character width: even assuming that a bigger width would be possible and a fixed width font is being used, that caret width would be absolute and doesn't consider the font width;
- it completely covers the following character(s), making them invisible if they're smaller than the caret;
We need another, and more appropriate solution.
QScintilla is a Qt port of Scintilla, and, similarly to PyQt, its documentation is either non existent or irrelevant, if not misleading (as it is for PySide in most cases).
While for Qt Python bindings it's normally enough to rely on the official C++ docs, QScintilla forces us to use the original Scintilla documentation.
The Scintilla interface works through "messages" sent to its control, with the first parameter being the target parameter/option/etc. and the following being the possible arguments.
Most of the general use functions are already implemented in QScintilla (and its Python binding), but for anything else, it's necessary to use the above interface through the SendScintilla()
function, implemented in the QsciScintillaBase
, from which QsciScintilla inherits. Most of the QScintilla functions are actually wrappers around that functions.
By looking at the documentation above, we can find that it is possible to use the SCI_SETCARETSTYLE
message, followed by the wanted style, that also includes a CARETSTYLE_BLOCK
.
Therefore, the solution is relatively simple and effective, once you know how Scintilla works:
editor.SendScintilla(editor.SCI_SETCARETSTYLE, editor.CARETSTYLE_BLOCK)
本文标签: pythonExtra wide CARET in QScintilla and PyQt6Stack Overflow
版权声明:本文标题:python - Extra wide CARET in QScintilla and PyQt6 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741296930a2370870.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论