GVKun编程网logo

无法在PyQt5中导入QtWebKitWidgets(pyqt5安装后导入包找不到)

11

关于无法在PyQt5中导入QtWebKitWidgets和pyqt5安装后导入包找不到的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于c–从QtWebKit到QtWebEngine的QWe

关于无法在PyQt5中导入QtWebKitWidgetspyqt5安装后导入包找不到的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于c – 从QtWebKit到QtWebEngine的QWebView :: settings() – > setUserStyleSheetUrl()?、centos 7.5安装temviewer14,遇到qt5-qtwebkit问题解决以及文件下载地址、Differences Between PyQt4 and PyQt5、HT for Web嵌入QtWebKit的客户端解决方案等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

无法在PyQt5中导入QtWebKitWidgets(pyqt5安装后导入包找不到)

无法在PyQt5中导入QtWebKitWidgets(pyqt5安装后导入包找不到)

我最近在这里使用Windows
32位安装程序将PyQt5从5.5.1升级到了5.6.0:https
://www.riverbankcomputing.com/software/pyqt/download5 。我还将python从3.4升级到3.5。

当我使用最新版本运行旧代码(该代码曾经可以工作)时,出现异常:

    from PyQt5.QtWebKitWidgets import *ImportError: No module named ''PyQt5.QtWebKitWidgets''

我在python中进行的所有QT调用都是连续发生的(并且,我知道我不应该导入*,但是我认为这是问题所在):

        from PyQt5.QtCore import *        from PyQt5.QtGui import *        from PyQt5.QtWidgets import *        from PyQt5.QtWebKitWidgets import *

因此,QtCore,QtGui和QtWidgets导入都可以。

另外,当我在源代码中搜索QtWebKitWidgets时,会出现对该模块的一些引用。

最后,我的python路径如下所示:

C:\PYTHON35;C:\PYTHON35\DLLs;C:\PYTHON35\LIB;C:\PYTHON35\LIB\LIB-TK;

和环境路径:

C:\Python35\Lib\site-packages\PyQt5;C:\Python35;C:\Python35\Lib;C:\Python35\Lib\site-packages;C:\Python35\Scripts ....

答案1

小编典典

QtWebKit在Qt
5.5中被上游弃用,在5.6中被删除。

您可能要切换到PyQt5.QtWebEngineWidgets:

这取代了QtWebKit模块,并为HTML,CSS和JavaScript功能提供了更好的最新支持。

c – 从QtWebKit到QtWebEngine的QWebView :: settings() – > setUserStyleSheetUrl()?

c – 从QtWebKit到QtWebEngine的QWebView :: settings() – > setUserStyleSheetUrl()?

我正在将我的代码从Qt 5.5升级到Qt 5.6,但我没有找到一种方法来移植以下代码:

QWebEngineView *qwebview = new QWebEngineView(this);
qwebview->settings()->setuserstylesheetUrl(QUrl("qrc:/about.css"));
qwebview->setHtml(fileContentStr);

使用新的Qt Web引擎插入用户CSS的最佳方法是什么?

解决方法

如果你在这里阅读: Bug Report on QWebEngine,你会看到:

The only opportunity to inject CSS code into the WebEngineView is
using JavaScript. It would be nice to have an appropriate API for this
and it Could look like our already existing UserScripts API.

看起来很清楚:你不能再使用WebSettings来插入CSS了.相反,您将不得不使用HTML / JavaScript来做到这一点.

我不知道它是否会对你有所帮助,但这里有我所做过的摘录.

在我的.cpp中:

m_pView = new QWebEngineView(this);

QUrl startURL = QUrl("path/to/index.html");

m_pView->setUrl(startURL);

在index.html中:

<html>
    <head>
        <title>TITLE</title>
        <Meta charset="UTF-8">
        <Meta name="viewport" content="width=device-width,initial-scale=1.0">

        <!-- Many JS scripts here -->

        <link href="./css/style.css" rel="stylesheet">

    </head>
    <body ng-app="myApp" >
      <div ui-view></div>
    </body>
</html>

希望有所帮助.

centos 7.5安装temviewer14,遇到qt5-qtwebkit问题解决以及文件下载地址

centos 7.5安装temviewer14,遇到qt5-qtwebkit问题解决以及文件下载地址

warning: teamviewer_14.2.8352.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 0c1289c0: NOKEY
error: Failed dependencies:
	libQt5Qml.so.5()(64bit) >= 5.5 is needed by teamviewer-14.2.8352-0.x86_64
	libQt5Quick.so.5()(64bit) >= 5.5 is needed by teamviewer-14.2.8352-0.x86_64
	libQt5WebKit.so.5()(64bit) >= 5.5 is needed by teamviewer-14.2.8352-0.x86_64
	libQt5WebKitWidgets.so.5()(64bit) >= 5.5 is needed by teamviewer-14.2.8352-0.x86_64
	libQt5X11Extras.so.5()(64bit) >= 5.5 is needed by teamviewer-14.2.8352-0.x86_64
	qt5-qtdeclarative >= 5.5 is needed by teamviewer-14.2.8352-0.x86_64
	qt5-qtquickcontrols >= 5.5 is needed by teamviewer-14.2.8352-0.x86_64

下面是安装命令行以及下载地址

wget https://download.teamviewer.com/download/linux/teamviewer_14.0.12762.x86_64.rpm 
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/q/qt5-qtwebkit-5.9.1-1.el7.x86_64.rpm 
yum -y install qt5-qtwebkit-5.9.1-1.el7.x86_64.rpm yum -y install teamviewer_14.0.12762.x86_64.rpm

如果失败,请访问该网站最下面有下载选项。

http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/q/qt5-qtwebkit-5.9.1-1.el7.x86_64.rpm

Differences Between PyQt4 and PyQt5

Differences Between PyQt4 and PyQt5

Differences Between PyQt4 and PyQt5

PyQt5 is not compatibile with PyQt4 (although experience shows that the effort in porting applications from PyQt4 to PyQt5 is not great). This section describes the main differences between the two.

Supported Python Versions

Versions of Python earlier than v2.6 are not supported.

Deprecated Features

PyQt5 does not support any parts of the Qt API that are marked as deprecated or obsolete in Qt v5.0. However it is possible that some of these have been included accidentaly. These are considered bugs and will be removed if found.

Multiple APIs

PyQt4 supports a number of different API versions (QStringQVariant etc.). With the exception of QVariant, PyQt5 only implements v2 of those APIs for all versions of Python. The changed support for QVariant, including the removal of QPyNullVariant, is described in Support for QVariant.

Old-style Signals and Slots

PyQt4’s old-style signals and slots are not supported. Therefore the following are not implemented in PyQt5:

All methods that had arguments that are usually the results of calls to SIGNAL() or SLOT() are no longer supported. There will always be an equivalent that takes a bound signal or callable respectively.

In addition the following methods have differences:

New-style Signals and Slots

Qt implements signals with an optional argument as two separate signals, one with the argument and one without it. PyQt4 exposed both of these allowing you to connect to each of them. However, when emitting the signal, you had to use the signal appropriate to the number of arguments being emitted.

PyQt5 exposes only the signal where all arguments are specified. However it allows any optional arguments to be omitted when emitting the signal.

Unlike PyQt4, PyQt5 supports the definition of properties, signals and slots in classes not sub-classed from QObject (i.e. in mixins).

QtDeclarativeQtScript and QtScriptTools Modules

PyQt4’s QtDeclarativeQtScript and QtScriptTools modules are not supported. These have been replaced by PyQt5’s QtQml and QtQuick modules. Unlike PyQt4, PyQt5 supports the creation of Python objects from QML.

QtGui Module

PyQt4’s QtGui module has been split into PyQt5’s QtGuiQtPrintSupport and QtWidgets modules.

QtOpenGL Module

Only the QGLContextQGLFormat and QGLWidget classes are supported by PyQt5.

QtWebKit Module

PyQt4’s QtWebKit module has been split into PyQt5’s QtWebKit and QtWebKitWidgets modules.

QtXml Module

PyQt4’s QtXml module is not supported. Use either the QXMLStreamReader and QXMLStreamWriter classes or Python’s standard XML modules.

pyqtconfig Module

PyQt4’s pyqtconfig module is not supported. The section The PyQt5 Extension API describes the support that PyQt5 provides to third-party packages (e.g. QScintilla) that want to build on top of PyQt5.

dbus.mainloop.qt Module

PyQt4’s dbus.mainloop.qt module is called dbus.mainloop.pyqt5 in PyQt5. This allows them to be installed side by side. Their functionality is identical.

QDataStream

The readUInt8()readInt8()writeUInt8() and writeInt8() methods all interpret the values being read and written as numeric values. In PyQt4 they are interpreted as single character strings.

QFileDialog

The getOpenFileNameAndFilter()getOpenFileNamesAndFilter() and getSaveFileNameAndFilter() methods of PyQt4’s QFileDialog have now been renamed getOpenFileName(),getOpenFileNames() and getSaveFileName() respectively in PyQt5. PyQt4’s implementations of getOpenFileName()getOpenFileNames() and getSaveFileName() are not supported in PyQt5.

QGraphicsItemAnimation

Support for the deprecated QGraphicsItemAnimation class has been removed. If porting an existing PyQt4 application then consider first updating it to use QPropertyAnimationinstead.

QMatrix

Support for the deprecated QMatrix class has been removed. If porting an existing PyQt4 application then consider first updating it to use QTransform instead.

QPyTextObject

PyQt4 implements the QPyTextObject as a workaround for the inability to define a Python class that is sub-classed from more than one Qt class. PyQt5 does support the ability to define a Python class that is sub-classed from more than one Qt class so long as all but one of the Qt classes are interfaces, i.e. they have been declared in C++ as such usingQ_DECLARE_INTERFACE. Therefore QPyTextObject is not implemented in PyQt5.

QSet

In PyQt4, QSet was implemented as a list in Python v2 and a set in Python v3. In PyQt5 QSet is always implemented as a set.

pyuic5

pyuic5 does not support the --pyqt3-wrapper flag of pyuic4.

pyrcc5

pyrcc5 does not support the -py2 and -py3 flags of pyrcc4. The output of pyrcc5 is compatible with all versions of Python starting with Python v2.6.

Cooperative Multi-inheritance

Unlike PyQt4, PyQt5 classes implement cooperative multi-inheritance. In other words PyQt5 classes always do the equivalent of the following Python v3 code in their __init__methods (where kwds is a dictionary of unused keyword arguments):

super().__init__(**kwds)

This means that those unused keyword arguments are passed to the __init__ methods of any mixin classes. Those mixin classes must cooperate, i.e. they must make a similar call if they have their own __init__ implementations.

When using multiple inheritance in PyQt4 it is common to call the __init__ methods of the super-classes explicitly, for example:

class MyQObject(QObject, MyMixin):
    def __init__(self, parent, mixin_arg):
        QObject.__init__(self, parent)
        MyMixin.__init__(self, mixin_arg)

        # Other initialisation...

In PyQt5 the above would cause MyMixin.__init__ to be called twice. Instead it should be implemented as follows:

class MyQObject(QObject, MyMixin):
    def __init__(self, **kwds):
        super().__init__(**kwds)

        # Other initialisation...

Note that if there is no other initialisation to do then the __init__ method isn’t actually needed.

The mixin class should be implemented as follows:

class MyMixin:
    def __init__(self, mixin_arg, **kwds):
        super().__init__(**kwds)

        # Other initialisation...

If a class only inherits from a single class then it can still call the super-class’s __init__ method explicitly (although it is recommended to use super()).

See Support for Cooperative Multi-inheritance.

Releasing the GIL

The GIL is only released when it is known to be needed. PyQt4 always released the GIL when calling Qt.

Object Destruction on Exit

When the Python interpreter exits PyQt4 (by default) calls the C++ destructor of all wrapped instances that it owns. This happens in a random order and can therefore cause the interpreter to crash. This behavior can be disabled by calling the sip.setdestroyonexit() function.

PyQt5 always calls sip.setdestroyonexit() automatically. However if the wrapped instances have not been created at the module level and have instead been created in a function then the problem will still exist. For example, do not do the following:

def main():
    app = QApplication(sys.argv)

    w = QWidget()
    w.show()

    app.exec()

if __name__ == '__main__':
    main()

Instead, do the following:

if __name__ == '__main__':
    app = QApplication(sys.argv)

    w = QWidget()
    w.show()

    app.exec()

HT for Web嵌入QtWebKit的客户端解决方案

HT for Web嵌入QtWebKit的客户端解决方案

HTML5已经足够强大,但很多应用还是需要独立桌面客户端的解决方案,毕竟能操作本地文件等功能还是很多工具类软件短期内无法完全采用云方案替代。

hero

最近Adobe发布的http://brackets.io也是类似的应用,Brackets这样描述自己:An open source code editor for the web, written in JavaScript, HTML and CSS. 这样的描述在过去很难想象居然是编辑器的工具,如今采用WebKit嵌套各种壳的方案已让这类应用成为主流。

Adobe的Brackets采用的是自家的https://github.com/adobe/brackets-shell/套壳框架,不过brackets-shell仅为Brackets量身定做,并不建议一般应用使用:

Note: The brackets-shell is only maintained for use by the Brackets project. Although some people have definitely had success using it as an app shell for other projects, we don’t provide any official support for that and we haven’t done a ton of work to make the app shell easily reusable. Many people will likely find it easier to use a project like node-webkit, which is more generic by design.

一般应用采用https://github.com/rogerwang/node-webkit,HT for Web自然也能通过node-webkit打包成客户端应用程序,如下图所示:

22

最近遇到用户通过Qt将HT for Web嵌入QtWebKit的解决方案,但遇到了显示正常但无法鼠标操作的奇怪问题,经过一番折腾才发现HT居然把QtWebKit在桌面的环境,错误的识别为可Touch的移动终端环境,如何正确判断Touch和Mouse的交互环境是非常狗血的事情,可参考http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript/4819886#4819886 加上如今window8的即可touch又可mouse让问题更加复杂化。

还好HT预留了可配置的方案,通过在引入ht.js包之前设置htconfig = {Default: {isTouchable:false}};强制HT采用常规的mouse事件进行处理。因为HT内部简单采用”ontouchend” in document的方案来判断,一般情况下桌面环境该值为undefined,移动终端为null,而QtWebKit居然在桌面环境下也为null,结果HT采用了Touch的监听事件从而导致了无法操作的现象,通过htconfig的设置后一切就正常了!

Screen Shot 2014-11-14 at 12.11.54 AM

HTML5通过WebKit嵌入打包成本地应用已经不是新鲜事了,整个世界的各种客户端技术正在变得更加融合,无数种千奇百怪的客户端方案正在改变很多观点和架构,不久前的wwdc2014中的JavaScript for Automation我觉得是被严重忽略的亮点,整个mac osx系统和应用程序都可通过JavaScrpit进行调用,早期window得利于众多应用软件而普及,苹果在站稳了移动终端后,借助诸如JavaScript for Automation的动作吸引更多专业客户端开发者,也许会不知不觉在桌面领域翻盘。

Screen Shot 2014-11-14 at 1.27.25 AM


今天关于无法在PyQt5中导入QtWebKitWidgetspyqt5安装后导入包找不到的讲解已经结束,谢谢您的阅读,如果想了解更多关于c – 从QtWebKit到QtWebEngine的QWebView :: settings() – > setUserStyleSheetUrl()?、centos 7.5安装temviewer14,遇到qt5-qtwebkit问题解决以及文件下载地址、Differences Between PyQt4 and PyQt5、HT for Web嵌入QtWebKit的客户端解决方案的相关知识,请在本站搜索。

本文标签: