Results 1 to 2 of 2

Thread: How to restore the position of the textCursor?

  1. #1
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default How to restore the position of the textCursor?

    Hi all, I use a QTextEdit to let the user insert a text. Additionaly, I let the user change the font style of this text with a button connected to a slot where I call QFontDialog::getFont. When the user changes the font, I reflect it in the text edit by reinserting all the text in the text edit:
    Qt Code:
    1. textEdit -> setCurrentFont(font);
    2. textEdit -> setPlainText(textEdit -> toPlainText());
    To copy to clipboard, switch view to plain text mode 
    The problem is that the textCursor of the text edit doesn't maintains the old position and it appears at the begining of the text. Is it an easy way to restore the "old" position of the text cursor?

    PD: I've tried it by getting the text cursor before calling to setPlainText and setting it again after but it doesn't works
    Last edited by Dark_Tower; 25th April 2006 at 17:13.

  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 restore the position of the textCursor?

    Did I understand correctly that you intend always to change the font of the whole text edit widget?
    If so, use simply:
    Qt Code:
    1. textEdit->setFont(font)
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    Dark_Tower (26th April 2006)

Similar Threads

  1. QTextEdit restore cursor position
    By artur231 in forum Qt Programming
    Replies: 3
    Last Post: 15th May 2014, 22:02

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.