5

I I have an editable QWebView, and would like to get the position (QPoint) of TextCursor. I searched but could only find the position of the cursor (mouse pointer) webview-> cursor.pos (); and this position is not what I want.

Anyone have any suggestions?

Thank you!

General Grievance
  • 4,555
  • 31
  • 31
  • 45
FelipeMac
  • 71
  • 7
  • So, what do you want? QPoint? Fine. Global? Local? Local to what widget? Perhaps you give a small explanation what you want to do. I can't think of any use case, which needs the QPoint position of a TextCursor. – Greenflow Aug 14 '13 at 17:39
  • So, I have an editable QWebView and accurate position TextCursor (Qpoint) in WebView to set as the center in implementing a ZOOM, like the WordPad (MS Windows). – FelipeMac Aug 15 '13 at 11:05
  • I see. I don't think this is possible. QTextCursor is no graphical element with a defined position on screen. It is a logical position within a text. What you want to do is identical to find the screen position of the gap between two letters in a text. There is no easy function for that. Counting pixels using font parameters is probably far too complicated and error prone. – Greenflow Aug 15 '13 at 11:26
  • Well, when I implemented this type of ZOOM in a textedit was very easy to get the position, I used textedit-> TextCursor () to get the TextCursor and then I configured the the area cursor to get the correct position: textedit-> cursorRect (textedit-> TextCursor ()). center This command I returned to the center position where he was the TextCursor. – FelipeMac Aug 15 '13 at 11:52
  • Bah, stupid me. Of course. Functionality like this makes sense in QTextEdit. – Greenflow Aug 15 '13 at 12:19
  • yeah, in qtextedit this functionality is easy, but now i'm using qwebview editable and was complicated. – FelipeMac Aug 15 '13 at 12:22
  • webview->page()->inputMethodQuery(Qt::ImMicroFocus).toRect ().center() Thank you for helping me!!! – FelipeMac Aug 16 '13 at 11:20
  • You should make this a proper answer. No trivial question at all. I am sure others could get the same problem. I at least made myself a note with your solution. – Greenflow Aug 16 '13 at 13:57
  • @Greenflow I am still learning how things work around here. Thanks for the tip! – FelipeMac Aug 16 '13 at 14:39

1 Answers1

4

Resolved, to catch the QPoint TextCursor in editable QWebView is used:

webview->page ()->inputMethodQuery(Qt::ImMicroFocus).toRect ().center()

(for example: center() )

Thanks to those who helped me!

FelipeMac
  • 71
  • 7