PDA

View Full Version : How to select the contents of <a ..> .. </a> in a QTextBrowser



Berryblue031
25th May 2011, 13:31
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


//"this" extends QTextBrowser
connect(this, SIGNAL(highlighted(const QString&)), this, SLOT(onLinkHover(const QString&)));

void onLinkHover(const QString& link)
{
if(link.contains("specialToHoverFlag"))
{
QTextCursor tc = cursorForPosition(mapFromGlobal(QCursor::pos()));
tc.select(QTextCursor::WordUnderCursor);
setTextCursor(tc);
}
else
{
QTextCursor tc = textCursor();
tc.clearSelection();
setTextCursor(tc);
}
}

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) ; ?