Results 1 to 7 of 7

Thread: How to synchronize text cursor and cursor in QTextEdit

  1. #1
    Join Date
    Sep 2006
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to synchronize text cursor and cursor in QTextEdit

    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?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to synchronize text cursor and cursor in QTextEdit

    You have to apply the cursor movement by setting the cursor on the text edit:
    QTextEdit::setTextCursor()
    J-P Nurmi

  3. #3
    Join Date
    Sep 2006
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to synchronize text cursor and cursor in QTextEdit

    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?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to synchronize text cursor and cursor in QTextEdit

    Sounds like there might be something wrong with the technique of moving the cursor. Are you doing it like this:
    Qt Code:
    1. QTextCursor cursor = textEdit->textCursor(); // retrieve the visible cursor
    2. cursor.movePosition(QTextCursor::End); // move/modify/etc.
    3. textEdit->setCursor(cursor); // apply visible cursor
    To copy to clipboard, switch view to plain text mode 
    ?
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Location
    Scandinavia
    Posts
    62
    Thanks
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to synchronize text cursor and cursor in QTextEdit

    I have the same problem with "synching" of the Text Cursor

    Quote Originally Posted by jpn View Post
    Sounds like there might be something wrong with the technique of moving the cursor. Are you doing it like this:
    Qt Code:
    1. textEdit->setCursor(cursor); // apply visible cursor
    To copy to clipboard, switch view to plain text mode 
    ?
    This does not work - do you mean instead
    Qt Code:
    1. textEdit->setTextCursor(cursor); // apply visible cursor
    To copy to clipboard, switch view to plain text mode 

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

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to synchronize text cursor and cursor in QTextEdit

    Quote Originally Posted by KjellKod View Post
    IThis does not work - do you mean instead
    Qt Code:
    1. textEdit->setTextCursor(cursor); // apply visible cursor
    To copy to clipboard, switch view to plain text mode 
    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.
    J-P Nurmi

  7. #7
    Join Date
    Jan 2006
    Location
    Scandinavia
    Posts
    62
    Thanks
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to synchronize text cursor and cursor in QTextEdit

    Quote Originally Posted by jpn View Post
    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

    Quote Originally Posted by jpn View Post
    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-p...post29477.html

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.