Results 1 to 9 of 9

Thread: QTextEdit question

  1. #1
    Join Date
    Sep 2011
    Posts
    6
    Qt products
    Qt3
    Platforms
    MacOS X

    Default QTextEdit question

    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?

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTextEdit question

    You can access base's protected member functions from within derived class (this will be an issue only if the member is declared private).

  3. #3
    Join Date
    Sep 2011
    Posts
    6
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: QTextEdit question

    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?

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTextEdit question

    The obvious answer is: derive a class from QTextEdit, into that class code a public member function that returns whatever the textCursor() returns and use this class as parameter.

    //Also if possible upgrade to Qt4, in between other improvement textCursor has become a public member.

  5. #5
    Join Date
    Sep 2011
    Posts
    6
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: QTextEdit question

    Thanks for the answer. I'll try that tomorrow

  6. #6
    Join Date
    Sep 2011
    Posts
    6
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: QTextEdit question

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

  7. #7
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTextEdit question

    Try to #include <QTextCursor>, this sounds like the compiler could not find the class' definition.

  8. #8
    Join Date
    Sep 2011
    Posts
    6
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: QTextEdit question

    This is not possible. it's a private class

  9. #9
    Join Date
    Sep 2011
    Posts
    6
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: QTextEdit question

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

Similar Threads

  1. Simple question about QTextEdit
    By maverick_pol in forum Qt Programming
    Replies: 1
    Last Post: 6th March 2008, 17:52
  2. QTextEdit simple question
    By Marcopolo in forum Qt Tools
    Replies: 4
    Last Post: 11th October 2007, 00:01
  3. a question about visualizing cursor in read-only QTextEdit
    By kennyxing in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2006, 19:52
  4. newbie question about qtextedit fields
    By otortos in forum Qt Programming
    Replies: 1
    Last Post: 23rd February 2006, 18:21
  5. QTextEdit Qt4: simple question
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 18th January 2006, 12:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.