Qt 或 PyQt4 - 我如何才能拔出和嵌入 YouTube 剪辑的盒子? [英] Qt or PyQt4 - How can i pull out and embed Only the box of YouTube clip?

查看:24
本文介绍了Qt 或 PyQt4 - 我如何才能拔出和嵌入 YouTube 剪辑的盒子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 QWebView 作为其中央小部件创建一个窗口,并在其中仅设置 youtube 剪辑框,而没有该 youtube 网页上的其余信息.

I'm trying to create a window with QWebView as its central widget and set inside it only the youtube clip box without the rest of the information on that youtube webpage.

YouTube 链接可以根据用户的要求进行更改.

The YouTube links can change by request of the user.

我发现了这个示例它以这种方式工作.

I found this example where it works that way.

只有链接地址有不同的形式:http://www.youtube.com/v/nKIu9yen5nc而不是通常的形式:http://www.youtube.com/watch?v=nKIu9yen5nc

only the link address has a different form: http://www.youtube.com/v/nKIu9yen5nc instead of the usual form: http://www.youtube.com/watch?v=nKIu9yen5nc

但并非 youtube 中的所有链接都能够以这种方式显示.

But not all links in youtube are capable shown that way.

推荐答案

好的.我找到了一个简单的解决方案.所以我写信以防有人会得到它的帮助.(即使我是 python 和 pyqt 的菜鸟)

Ok. I have found a simple solution. So i write in case someone would be helped by it.(even i'm a noob to python and pyqt)

我在 youtube 网站本身中使用了嵌入选项的代码,并添加了 html 标签,使其成为网页的完整代码.然后我使用 QWebView.setHtmel() 将该代码设置为要在 QWebView 上呈现的页面.它有效:-).

I used the code of the Embed option in youtube site itself and added html tags to make it a complete code for a web page. Then i used QWebView.setHtmel() to set that code as the page to be rendered on the QWebView. And it works :-).

view = QWebView()
s =QString("""<!DOCTYPE html>
                         <html>
                         <body>
                         <iframe width="560" height="315" src="//www.youtube.com/embed/1VQ_3sBZEm0" frameborder="0" allowfullscreen></iframe>
                         </body>
                         </html>""")

view.setHtml(s,QUrl('https://youtube.com'))

这篇关于Qt 或 PyQt4 - 我如何才能拔出和嵌入 YouTube 剪辑的盒子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆