PDA

View Full Version : How to synchronize text cursor and cursor in QTextEdit



kennyxing
9th October 2006, 04:23
How can I synchronize QTextCursor and the display cursor in QTextEdit? For example, when I move the text cursor,how can I move the display cursor to the same position?

jpn
9th October 2006, 07:16
You have to apply the cursor movement by setting the cursor on the text edit:
QTextEdit::setTextCursor()

kennyxing
10th October 2006, 11:42
The problem is, after I set the text cursor, although I can move around the text cursor, the blinking display cursor does not move. That's why I want to synchronize them.

Another situation is, when I change the position of the blinking display cursor by clicking the mouse, how can I move the text cursor to the same position?

jpn
10th October 2006, 11:56
Sounds like there might be something wrong with the technique of moving the cursor. Are you doing it like this:


QTextCursor cursor = textEdit->textCursor(); // retrieve the visible cursor
cursor.movePosition(QTextCursor::End); // move/modify/etc.
textEdit->setCursor(cursor); // apply visible cursor

?

KjellKod
17th February 2007, 15:22
I have the same problem with "synching" of the Text Cursor


Sounds like there might be something wrong with the technique of moving the cursor. Are you doing it like this:


textEdit->setCursor(cursor); // apply visible cursor

?

This does not work - do you mean instead


textEdit->setTextCursor(cursor); // apply visible cursor


Sure, that sets the cursor. BUT clicking anywhere on the screen then moves the current "invisible" cursor -while the inactive cursor is shown.

jpn
17th February 2007, 16:25
IThis does not work - do you mean instead


textEdit->setTextCursor(cursor); // apply visible cursor


Yes indeed, that's what I meant. Sorry for the typo.


Sure, that sets the cursor. BUT clicking anywhere on the screen then moves the current "invisible" cursor -while the inactive cursor is shown.
Sorry, I don't understand what you mean. Could you rephrase? What are "invisible" and "inactive" cursors?

Clicking on a QTextEdit will move the cursor at the clicked point. Do you want to avoid that? Then you will have to subclass and override mousePressEvent() or install an event filter to prevent the QTextEdit implementation from handling the mouse press event.

KjellKod
18th February 2007, 10:14
Sorry, I don't understand what you mean. Could you rephrase? What are "invisible" and "inactive" cursors?
Me bad! I tried to use some good words that would explain the problem - but I think I didn't do a good job


Clicking on a QTextEdit will move the cursor at the clicked point. Do you want to avoid that? No, not at all - that's exactly what I want. However the problem is that the "cursor" where new input from keyboard is moved to where you click, but the visible cursor symbol doesn'tmove where you click. I.e. you end up with a visible cursor symbol in one place and when you type the text will be inserted at the invisible cursor...

Sorry, I don't want to hijack this thread (although they sound the same)- I've started another thread which explains exactly what the problem is.

http://www.qtcentre.org/forum/f-qt-programming-2/t-drag-n-drop-with-cut-and-not-copy-5699-post29477.html