Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is a question about the cursor in the qscintilla, not an issue #45

Closed
Mr-ZBin opened this issue Dec 3, 2021 · 4 comments
Closed

Comments

@Mr-ZBin
Copy link

Mr-ZBin commented Dec 3, 2021

Hi matkuki,
I have a question about how to get the cursor position in the screen? The statement self.cursor() returns the mouse position, and also self.getCursorPosition() only return the line and col number. But in the QPlainTextEdit, we can get the cursor position in the screen by using self.cursorRect(). I want use this position to create the auto complete panel instead of default completion in the qscintilla.
I have researched in "https://www.scintilla.org/ScintillaDoc.html" and looked it into the google for many days, but still not find the solution.
Do you know any solution about this?
Thank you very much,
Bin

@Mr-ZBin Mr-ZBin changed the title This is a question about the cursor in the qscintilla, not a issue This is a question about the cursor in the qscintilla, not an issue Dec 3, 2021
@matkuki
Copy link
Owner

matkuki commented Dec 4, 2021

Hi @Mr-ZBin ,

Funny you brought this up, as I also had the idea to make a custom autocompletion popup.
I just check the source code of QScintilla and this seems to be a very convoluted thing, internally it uses many objects and converter functions to switch between POINT, Point and QPoint. But I couldn't get to the bottom of it yet.

I have posted a question on the mailing list and will poke around the source a bit more. Will report back when something comes up.

@matkuki
Copy link
Owner

matkuki commented Dec 4, 2021

I have just gotten a reply on the mailing list:

Use the low-level SendScintilla API:
https://www.riverbankcomputing.com/static/Docs/QScintilla/classQsciScintillaBase.html#a8820ab8d7563bd7ed24ce6384846079e
Then you can get the x, y with:
https://www.scintilla.org/ScintillaDoc.html#SCI_POINTXFROMPOSITION
https://www.scintilla.org/ScintillaDoc.html#SCI_POINTYFROMPOSITION

Basically use:

x = editor.SendScintilla(QsciScintilla.SCI_POINTXFROMPOSITION, editor.positionFromLineIndex(editor.getCursorPosition()))
y = editor.SendScintilla(QsciScintilla.SCI_POINTYFROMPOSITION, editor.positionFromLineIndex(editor.getCursorPosition()))

I will try it later.

@matkuki
Copy link
Owner

matkuki commented Dec 4, 2021

@Mr-ZBin
Tested it and it works, with a slight adjustment:

x = editor.SendScintilla(QsciScintilla.SCI_POINTXFROMPOSITION, 0, editor.positionFromLineIndex(*editor.getCursorPosition()))
y = editor.SendScintilla(QsciScintilla.SCI_POINTYFROMPOSITION, 0, editor.positionFromLineIndex(*editor.getCursorPosition()))

@matkuki matkuki closed this as completed Dec 4, 2021
@Mr-ZBin
Copy link
Author

Mr-ZBin commented Dec 5, 2021

Hi matkhui,
Thank you very much. Now I use the first visible line number and the current line number and column number in the line to calculate the position in screen by fontMetrics(). But it's not precise when I zoom in or out.
Thank you very much for this reply. And your wonderful ExCo project helps me a lot because I'm a new user in python and pyqt.
Thanks,
Bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants