Results 1 to 4 of 4

Thread: Put selected in QTextEdit text into tags

  1. #1
    Join Date
    Oct 2011
    Posts
    51
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Put selected in QTextEdit text into tags

    Hi!

    I have a QTextEdit in which I want to implement <s>...</s> html tag (after pushing a button, selected text should be striked) how can I do this properly?

    Thanks for answers!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Put selected in QTextEdit text into tags

    It is a shame that the supported HTML subset offers none of the strike, s, or del HTML markup options. The QTextEdit should support using a span with a style using "text-decoration: line-through" So you might be able to get away just doing a search and replace before calling setHtml() (or after toHtml()). Can that achieve what you want?

  3. #3
    Join Date
    Oct 2011
    Posts
    51
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Put selected in QTextEdit text into tags

    Not exactly.
    What I want to do is add a "strike" option to text editor, so text "this is a very short text" (imagine that bolded text is selected in text editor) after clicking "strike" button editor should change selected text to striked. All I need to do is cut "very short" put it into tags like "<s>very short</s>" and paste it the same point as HTML. But I don't know how to do this, and I don't want to use cut and paste methods, because, when I do so there will be 2 steps to Undo (first "cut" operation and "paste" operation) or that is what I think will happen...

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Put selected in QTextEdit text into tags

    You probably need to do this by operating directly on the QTextDocument of the editor. When the strikeout button is clicked you merge a QTextCharFormat into the selected text. The text editor example shows how to do this:
    http://qt-project.org/doc/qt-5/qtwid...t-example.html
    Look at the textBold() and mergeFormatOnWordOrSelection() iFunctions n textedit.cpp and use QTextCharFormat::setStrikeout() instead.

Similar Threads

  1. QTextEdit. To make selected text as Bold.
    By KIBSOFT in forum Qt Programming
    Replies: 5
    Last Post: 14th December 2016, 11:47
  2. Replies: 1
    Last Post: 13th April 2012, 10:05
  3. QTextEdit <body> tags text only
    By certqt in forum Qt Programming
    Replies: 3
    Last Post: 22nd January 2011, 14:11
  4. Getting All Text Between Tags in XML ?
    By seanmu13 in forum Qt Programming
    Replies: 1
    Last Post: 8th June 2007, 17:29
  5. coordinates of selected text in QTextEdit
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2006, 18:22

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.