Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get coordinates of text cursor and map to parent coordinates?
Forum Updated to NodeBB v4.3 + New Features

How to get coordinates of text cursor and map to parent coordinates?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 363 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Inhahe
    wrote on last edited by Inhahe
    #1

    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!

    jsulmJ 1 Reply Last reply
    0
    • I Inhahe

      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!

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • I Offline
        I Offline
        Inhahe
        wrote on last edited by Inhahe
        #3

        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()))

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved