View Full Version : QTextEdit question
xsaridis
30th September 2011, 21:21
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?
Zlatomir
1st October 2011, 00:37
You can access base's protected member functions from within derived class (this will be an issue only if the member is declared private).
xsaridis
1st October 2011, 08:52
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?
Zlatomir
1st October 2011, 08:59
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 (http://doc.qt.nokia.com/latest/qtextedit.html#textCursor) has become a public member.
xsaridis
2nd October 2011, 21:54
Thanks for the answer. I'll try that tomorrow
xsaridis
3rd October 2011, 12:14
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...
stampede
3rd October 2011, 12:32
Try to #include <QTextCursor>, this sounds like the compiler could not find the class' definition.
xsaridis
4th October 2011, 09:22
This is not possible. it's a private class
xsaridis
6th October 2011, 17:20
Hello,
I added this header:
#include <private/qrrichtext_p.h>
and it works. Many thanks again!!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.