Reputation: 2605
I am just trying to write a code to open file by clicking a link which is displayed in QTextBrowser. But file is not getting open instead it is displaying in QTextBrowser itself. Here is my code
void MainWindow::openTextEdit()
{
QTextBrowser *p = new QTextBrowser();
p->show();
p->append("<a href = \"/home/winbros/Test.cpp\"> Link </a>");
p->append("<a href = \"/home/winbros/Test.doc\"> Link </a>");
p->append("<a href = \"/home/winbros/Test.xls\"> Link </a>");
p->setOpenExternalLinks(true);
}
I am using QT creator. Guys please let me know to use anchor clicked in this sense.
Upvotes: 2
Views: 2223
Reputation: 11227
It sounds like the anchorClicked signal could be useful to you. It contains the URL of the clicked link as a QUrl
.
Edit: OP asks for a usage example. I don't have time for that right now, but here's roughly what I would do:
foo
that takes a const QUrl&
.foo
can use QUrl::toLocalFile
to construct a QFile
and open it.QTextBrowser
's anchorClicked
signal to foo
.Upvotes: 2