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 a QPoint from a cursor position in QLineEdit
Qt 6.11 is out! See what's new in the release blog

How to get a QPoint from a cursor position in QLineEdit

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 6.9k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    lepepper
    wrote on last edited by
    #1

    Is there a way a to get a QPoint position from a cursorposition in QLIneedit.
    I can get the cursor position from QPoint, and not the otherway around Any Ideas??
    @
    int QLineEdit::cursorPositionAt ( const QPoint & pos )
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Maybe "QLineEdit::cursorRect() ":http://doc.qt.nokia.com/stable/qlineedit.html#cursorRect is of use for you (the cursor is a shape and does not have a "point" property). Be aware, the method is protected, you will have to subclass QLineEdit in order to access it.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lepepper
        wrote on last edited by
        #3

        Thanks Already I Have tried this,we do not get the cursor QPoint relative to lineedit,It is x val is always -1

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          I am curious: What do you want to do with the QPoint value?

          I think the only way to get an approximation of this information is to use QFontMetrics to calculate the positions of the individual characters...

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            The cursor position is relative to the start of the text. If your cursor is at the beginning of the text (i.e. before the very first character or with an empty text), it is < 0 (platform dependend), if you move the cursor, the rect moves and the x position is the pixel(s) between the two characters where the cursor is positioned. Everything works for me.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mohsen
              wrote on last edited by
              #6

              if you need the text width, try other solutions
              http://doc.qt.nokia.com/4.7/qfontmetrics.html

              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