Results 1 to 1 of 1

Thread: How to select the contents of <a ..> .. </a> in a QTextBrowser

  1. #1
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to select the contents of <a ..> .. </a> in a QTextBrowser

    I have a qtextdocument that displays an html document and when a link is moused over I need to select the contents of that link. This is easy enough when the link is a single word, but it could be a sentence for example <a .. >I am a linked sentence</a>, when it is a sentence I need to highlight the whole sentance and I can't find a very elegant solution.

    This is my current implementation

    Qt Code:
    1. //"this" extends QTextBrowser
    2. connect(this, SIGNAL(highlighted(const QString&)), this, SLOT(onLinkHover(const QString&)));
    3.  
    4. void onLinkHover(const QString& link)
    5. {
    6. if(link.contains("specialToHoverFlag"))
    7. {
    8. QTextCursor tc = cursorForPosition(mapFromGlobal(QCursor::pos()));
    9. tc.select(QTextCursor::WordUnderCursor);
    10. setTextCursor(tc);
    11. }
    12. else
    13. {
    14. QTextCursor tc = textCursor();
    15. tc.clearSelection();
    16. setTextCursor(tc);
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    Suggestions?


    Added after 1 56 minutes:


    Is it possible to markup my html in such a way so that the link is still displayed inline but considered a block by QTextCursor::select(QTextCursor::BlockUnderCursor) ; ?
    Last edited by Berryblue031; 25th May 2011 at 12:31.

Similar Threads

  1. QTableView resizing to contents.
    By chris_helloworld in forum Qt Programming
    Replies: 2
    Last Post: 24th November 2010, 13:43
  2. Hide contents of different layouts
    By zarkzervo in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 13:59
  3. Export GraphicsView contents as JPG
    By Terabyte in forum Qt Programming
    Replies: 3
    Last Post: 5th January 2009, 19:15
  4. Complex button contents
    By spraff in forum Qt Programming
    Replies: 3
    Last Post: 11th November 2008, 15:17
  5. How can i get the contents size of QTextBrowser
    By m_e in forum Qt Programming
    Replies: 4
    Last Post: 25th December 2006, 14:14

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.