QWebView 不会在新窗口中打开链接,也不会启动外部应用程序来处理 pdf
我以这种方式使用 QWebView:
QWebView *window = new QWebView();
window->setUrl(QString("my url"));
window->show();
它有效。我可以看到我想要的html页面。 问题是这样的。默认情况下,如果我在链接上“右键单击”,则会显示“在新窗口中打开”操作,但如果我单击它,则不会发生任何情况。如果我在同一个链接上“左键单击”,它就会起作用。 所以问题是QWebView没有打开新窗口。有谁知道为什么?
我还有另一个问题。有些链接是 pdf 文件,所以我希望 QWebView 要求我下载它或运行应用程序来打开它。但什么也没发生。我认为问题与 QWebView 不允许打开新窗口以及 pdf 上不允许打开新窗口有关。
显然,我使用网络浏览器测试了该页面,一切正常,因此问题出在 QWebView 的某些设置中。
有谁知道如何让 QWebView 在需要时打开新窗口?
注意:
所有链接都是本地资源。
html 链接使用此语法(并且它们有效):
一些链接
- pdf 的链接使用以下语法(单击时没有任何反应):
一些 pdf
I am using a QWebView in this way:
QWebView *window = new QWebView();
window->setUrl(QString("my url"));
window->show();
And it works. I can see the html page I want.
The problem is this. By default if I "right click" on a link the action "Open in new window" is shown but if I click on it, nothing happens. If I "left click" on the same link it works.
So the problem is that no new windows are open by QWebView. Does anyone know why?
I have another problem. Some links are pdf file so I expect that QWebView ask me to download it or to run an application to open it. But nothing happens instead. I think the problem is related to the fact that no new windows are allowed to be opened by QWebView and not on the pdf.
Obviously I tested the page with a web browser and everything work well, so the problem is in some settings of QWebView.
Does anyone know how to make QWebView open new windows when required?
Notes:
all links are local resources.
The html links use this syntax (and they works):
<a href="./something.htm" TARGET="_parent">Some link</a>
- The link to pdfs use this syntax (nothing happens when I click):
<a href="./pdf/mydoc.pdf" TARGET="pdfwin">Some pdf</a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试自己处理蜱虫。这是一个可以指导您的示例。我还没有编译它。
请注意,如果您显示的 HTML 可能包含指向其自身其他部分的相对/内部链接,那么您应该使用 QWebPage::DelegateExternalLinks 而不是 QWebPage::DelegateAllLinks。
Try to handle cicks by yourself. Here is an example that can guide you. I have not compiled it though .
Note that if the HTML you are displaying may containing relative/internal links to other parts of itself, then you should use
QWebPage::DelegateExternalLinks
instead ofQWebPage::DelegateAllLinks
.上面的答案内容丰富,但对于这个问题可能会不知所措。
将信号连接到 QWebPage::action(OpenLinkInNewWindow) 或重写 QWebPage::triggerAction 应该可以解决此问题。
The above answer is informative but might be overwhelmed for this question.
Connecting signals to QWebPage::action(OpenLinkInNewWindow) or overriding QWebPage::triggerAction should solve this problem.