想自己处理QTextBrowser打开链接,首先要setOpenLinks(false)。之后捕获anchorClicked信号,然后调用ShellExecute函数用系统默认浏览器打开url。参考代码如下
1 MainWindow::MainWindow(QWidget *parent) :
2 QMainWindow(parent),
3 ui(new Ui::MainWindow)
4 {
5 ui->setupUi(this);
6 ui->tBwsShow->setOpenLinks(false);
7
8 ui->tBwsShow->append(QString::fromLocal8Bit("<a href=\"http://www.baidu.com\">www.baidu.com</a>"));
9
10 connect(ui->tBwsShow,SIGNAL(anchorClicked(QUrl)),SLOT(on_tBwsShow_anchorClicked(QUrl)))
11 }
槽函数如下
1 void MainWindow::on_tBwsShow_anchorClicked(const QUrl &arg1)
2 {
3 ShellExecuteA(NULL, "open", url.toString().toStdString().c_str(), "", "", SW_SHOW);
4 }
posted on 2011-09-20 17:06
墙上的蜗牛 阅读(1700)
评论(0) 编辑 收藏 引用 所属分类:
Qt