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