Results 1 to 4 of 4

Thread: QTextEdit contents changed highlight the color

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Smile QTextEdit contents changed highlight the color

    Dear Friends
    I need your help in implementing a TextEdit….I have the functionality of saving option of the text available in the TextEdit. But everytime user loads a file and when starts editing the file the contents changed in the file should be highlighted with some color. And when save it it should return back to the original black & white color.
    I am not getting any idea about this. Any suggestions would be highly appreciated.

    QString contents;
    QTextEdit *textEdit = new QTextEdit(this);
    textEdit->setPlainText(contents);
    textEdit->show();

    Now after displaying the contents user wants to modify the contents, so all the contents only the modified part should be highlighted with some color, and when save it then come back to the normal mode.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTextEdit contents changed highlight the color

    Here is a tip:

    Set a default color format to QTextEdit using (say default color)

    Qt Code:
    1. void QTextEdit::setTextColor ( const QColor & c )
    To copy to clipboard, switch view to plain text mode 

    once the document is loaded, the the color to some editing color (color of your choice), so any text typed here onward will be in this color. When user saves the data then save text to file, fallback to the default color, clear the text in QTextEdit, load the text again, and set editing color again.

  3. #3
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: QTextEdit contents changed highlight the color

    Thats a good tip but I dont want to play with the text color but its background color or highlighting the text. What can be done for that.. Thanks for your reply.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTextEdit contents changed highlight the color

    Consider using one of the following.

    Qt Code:
    1. QColor QTextEdit::textBackgroundColor();
    2. void QTextEdit::setFontUnderline (bool underline); // text underline
    3. void QTextEdit::setFontPointSize(qreal s); // text size
    4. void QTextEdit::setFontWeight (int weight); // Normal, Bold etc
    5. void QTextEdit::setCurrentFont(const QFont & f);
    To copy to clipboard, switch view to plain text mode 

    Also read QTextEdit

Similar Threads

  1. Highlight an item in QCombobox by text color
    By AlekseyK in forum Qt Programming
    Replies: 6
    Last Post: 18th March 2019, 21:31
  2. How to Change QTreeView highlight color
    By jshafferman in forum Qt Programming
    Replies: 5
    Last Post: 6th May 2011, 17:13
  3. highlight in QTextEdit
    By ubuntudevelop78 in forum Qt Programming
    Replies: 1
    Last Post: 27th November 2009, 00:22
  4. Setting a highlight text color for QTableWidgetItem
    By Hiba in forum Qt Programming
    Replies: 6
    Last Post: 14th December 2007, 10:51
  5. Splitter Color changed when referesh?
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 11th July 2007, 08:10

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.