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"))
{
setTextCursor(tc);
}
else
{
tc.clearSelection();
setTextCursor(tc);
}
}
//"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);
}
}
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) ; ?
Bookmarks