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. QTextEdit question
Forum Updated to NodeBB v4.3 + New Features

QTextEdit question

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 5.5k 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.
  • X Offline
    X Offline
    xsaridis
    wrote on last edited by
    #1

    Hello everyone!!

    I'm using Qt 3.7 .
    I have a class that inherits QTextEdit and I would like to get the position of the text cursor (x() and y()).
    I can't use textCursor() function because it's protected.
    Do you have any suggestions?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      If you're inheriting from QTextEdit, why don't you have access to the protected members?

      As an aside, Qt 3 is very old. If possible, you're much better off using Qt 4 (if circumstances allow it.)

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

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

        In your subclass you have access to the protected method textCursor().

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

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xsaridis
          wrote on last edited by
          #4

          I'M CORRECTING MY PREVIOUS MESSAGE

          Hello everyone!!

          I'm using Qt 3.7 .
          I have a class that gets a QTextEdit as a parameter and I would like to get the position of the text cursor (x() and y()).
          I can't use textCursor() function because it's protected. (The class inherits a class that inherits QObject)
          Do you have any suggestions?

          1 Reply Last reply
          0
          • U Offline
            U Offline
            uranusjr
            wrote on last edited by
            #5

            Edit QTextEdit's header file and change textCursor() to public. :-)

            Just kidding. Qt 3 has a function called getCursorPosition that can get the current cursor position. You can consult the "online documentation":http://doc.qt.nokia.com/3.3/qtextedit.html for more information. (The doc is for Qt 3.3, but it's more or less the same. Does Qt 3.7 even exist? I didn't know that.)

            If you need information that are not accessible with existing functions, you can always subclass QTextEdit and write a custom public function that returns the current cursor, and use it in your project instead of QTextEdit.

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xsaridis
              wrote on last edited by
              #6

              Thank you all for your answers!! I will try it tomorrow

              1 Reply Last reply
              0
              • X Offline
                X Offline
                xsaridis
                wrote on last edited by
                #7

                Hello again,
                unluckily I couldn't made it.
                I've made a subclass that inherits QTextEdit and a public function:
                @
                getCursorCoordinates() {
                QTextCursor *tc = textCursor();
                int x = tc->globalX();
                int y = tc->globalY();
                }
                @
                and I had the error:
                request for member 'globalX' in 'tc', which is non-class type 'QTextCursor'.

                I think because QTextCursor is a private class.

                Any other help? I can't upgrade to Qt4..It's not up to me...

                Edit: Fixed code formatting. Please wrap code in @ tags; mlong

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

                  The class QTextCursor is not know to the compiler, which is ok as it is not in the public API and therefore not in the header files.

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

                  1 Reply Last reply
                  0
                  • X Offline
                    X Offline
                    xsaridis
                    wrote on last edited by
                    #9

                    Hi, I understand that I can't use QTextCursor :)
                    so is there something that you propose about finding cursor's position?

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

                      From what I remember of Qt3 days, no there is no such means. The only means that comes into mind would be to extract a class declaration (header file) out of the QTextCursor code in the Qt sources and include that into your own source files. But be aware that this might induce some license issues (speak of "derived work" in GPL). If you hold a commercial license, you're on the safe side.

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

                      1 Reply Last reply
                      0
                      • X Offline
                        X Offline
                        xsaridis
                        wrote on last edited by
                        #11

                        Hello,
                        I added this header:
                        #include <private/qrrichtext_p.h>
                        and it works. Many thanks again!!

                        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