How to get coordinates of text cursor and map to parent coordinates?
-
I want to pop up a QDialog right above where the text cursor is (in a QTextEdit) when the user types a certain key combination.
The QDialog won't actually appear over the QTextEdit because the QTextEdit's height is only the height of the font (so it looks sort of like a QLineEdit), so the QDialog will actually appear over another widget that's above the QTextEdit and within the QTextEdit's parent widget.
I need to know how to map the QTextEdit's cursor's coordinates to either parent coordinates or global coordinates (I'll figure out which one of those two I need).
The only way I've found to get coordinates of a QTextEdit's cursor is with my_qtextedit_object.cursorRect() or my_qtextedit_object.cursorRect().getRect(), but both of those results are incompatible with the my_qtextedit_object.mapToParent and my_qtextedit_object.mapToGlobal functions. They say QRect or tuple or whatever expected when it needed a QPoint.
Thanks for any help!
-
@Inhahe said in How to get coordinates of text cursor and map to parent coordinates?:
They say QRect or tuple or whatever expected when it needed a QPoint
Then simply take the upper left corner from the rect.
-
Thanks! I don't know how I overlooked that. It's obvious now that I know. =P
(I think the problem was that I called dir() on the QRect object to see what it contained instead of looking at the QT reference, and it wasn't there. (I think I had also looked at the QT reference before that and saw top() but not topLeft()))