我试图让QtWebEngine在VM上运行并且遇到困难.根据这个问题的答案:
最终我意识到OpenGL 3.3在虚拟机上不会轻易工作..但是.我不得不从ubuntu usb启动并通过安装最新的mesa 3d包来工作.
有没有办法让QtWebEngine在没有OpenGL的情况下工作?我不是直接使用任何OpenGL调用,也不需要任何3d功能.我只是想嵌入一个QWebEngineView来显示动态HTML页面.我猜这应该是可能的,因为Chrome可以在同一个VM上运行而不会出现问题.
我有一个Qt应用程序,用于启动Webview QWebChannel.
在这些视图中,我有JavaScript做一些事情,以根据屏幕大小定位/调整窗口大小.该screen对象应该提供这种信息.(屏幕文档)
但在我看来QWebEnginePage,在整个加载过程中屏幕对象都是空的.
如果我在一个按钮上放置一个监听器来到screen.height页面上的某个位置,现在它可以工作了.
//js local file called in html head
//screen = {}
document.addEventListener("load", function(event) {
//screen = {}
new QWebChannel(qt.webChannelTransport, function(channel) {
//screen = {}
//stuff
channel.object.myClass.show(function(res){ //Qt function that calls the show() method of the QWebEngineView
//screen = {}
});
});
document.getElementById("myBtn").addEventListener("click", function(){
console.log("height:" + screen.height); // screen: 1440
});
});
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,如何screen在JavaScript中的某个时刻访问值?
对于我的 PyQt5 浏览器项目的开发,我在这里QtWebEngineProcess.exe读到,通过将 Chrome 标志作为应用程序参数传递,它们将在代码启动时自动传递到。我已经尝试过这样做app = QApplication(sys.argv + [--enable-force-dark]),但这不会使铬以黑暗模式渲染网页(我也尝试了标志名称的很多变体,所以我认为这不是问题)。
我想知道是否可以通过继承一个类并覆盖一个函数,然后将其连接到此类,QtWebEngineProcess.exe从 PyQt5 代码中手动调用设置了自定义标志的函数,就像这样?QtWebEngineView...("QtWebEngineProcess.exe -[1st flag] -[2nd flag"])
如果上述方法不可行,是否有其他方法可以在QtWebEngineView?中使用带有自定义标志的 chromium?我在跑步PyQt5.14.2 (Chromium 77), Python 3.8.0, Windows 10
我延长了QWebEngineView.
#ifndef MYQWEBENGINEVIEW_H
#define MYQWEBENGINEVIEW_H
#include <QWebEngineView>
class MyQWebEngineView : public QWebEngineView
{
public:
MyQWebEngineView(QWidget *parent = 0);
~MyQWebEngineView();
protected:
virtual void paintEvent(QPaintEvent *);
};
#endif // MYQWEBENGINEVIEW_H
Run Code Online (Sandbox Code Playgroud)
但我不能被paintEvent(QPaintEvent *)召唤.
#include "myqwebengineview.h"
#include <QPaintEvent>
#include <QPainter>
#include <QWebEngineView>
#include <QWidget>
MyQWebEngineView::MyQWebEngineView(QWidget *parent):QWebEngineView(parent)
{
qDebug() << "MyQWebEngineView(" << parent << ")";
qDebug() << "Qt::WA_PaintOnScreen: " << testAttribute(Qt::WA_PaintOnScreen);
//setAttribute(Qt::WA_PaintOnScreen, true);
}
MyQWebEngineView::~MyQWebEngineView()
{
}
void MyQWebEngineView::paintEvent(QPaintEvent * event)
{
qDebug() << "paintEvent(" << event << ")";
QWebEngineView::paintEvent(event);
//QWidget::paintEvent(event); …Run Code Online (Sandbox Code Playgroud) 有没有人使用Microsoft Visual Studio C++ 2015在Windows上成功构建Qt的WebEngine/QtWebEngine/QWebEngine?
必要的先决条件是什么?
我设法自己构建Qt,但QtWebEngine被跳过了,所以我尝试nmake module-qtwebengine了失败有几个原因.
我正在将应用程序从QtWebKit升级到QtWebEngine.应用程序依赖于WebKit在关闭应用程序后没有保留cookie但WebEngine似乎默认保留它们.
我根本不熟悉Qt.我一直在浏览文档,但似乎无法找到正确的API调用来删除它们.该应用程序只有一个简单的QWebEngineView用于前端.
我正在努力将Qt 5.5,QWebView项目移植到Qt 5.6(beta),QWebEngine.我在这里看过移植指南.我的代码看起来像这样:
.h文件定义_view如下:
QWebEngineView* _view;
Run Code Online (Sandbox Code Playgroud)
并且.cpp构造函数(类继承自QWidget)具有:
QVBoxLayout* vbox = new QVBoxLayout(this);
_view = new QWebEngineView(this);
connect(_view, SIGNAL(loadFinished(bool)), this, SLOT(loadPageFinished(bool)));
QString webDir = getReportBasePath() + no_tr("/index.html#") + startingPage;
// QWebEnginePage *page = _view->page(); // <-- CRASH!!
_view->load( QUrl("file:///" + webDir ) ); // <-- CRASH!!
_view->show();
vbox->addWidget(_view);
Run Code Online (Sandbox Code Playgroud)
在执行page()或load()方法时,整个事情崩溃了:
Unhandled exception at 0x67019C66 (Qt5Cored.dll) in qxs.exe: 0xC0000005:
Access violation reading location 0x00000000.
Run Code Online (Sandbox Code Playgroud)
我已经验证了_view指针不是null.
如果您查看文档,他们在这里有一个示例,它几乎与我上面的代码完全相同.我也尝试将load()调用替换为与他们相同:
view->load(QUrl("http://qt-project.org/"));
Run Code Online (Sandbox Code Playgroud)
它仍然崩溃.什么可能导致这些崩溃的想法?
我是否需要首先创建QWebEnginePage并在QWebEngineView上创建setPage()?(我假设没有...)它是否与我正在使用的Qt二进制文件(预先为Windows 32位MSVC 2013构建)有关?
堆栈跟踪的相关部分:
Qt5WebEngineWidgetsd.dll!QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile * _profile) Line 95 …Run Code Online (Sandbox Code Playgroud) 我认为标题几乎解释了一切。
但是,您如何解释这两个有关在Qt应用程序中显示 Web 内容的术语的作用和用途?如果我使用 a WebView,它会自动涉及QtWebEngine还是其他?
我在维基百科上读到Qt使用Blink作为网络引擎,但是在Qt官方页面上他们没有Blink在任何地方提到这个术语。
我正在尝试从PyQt5应用程序内部加载和查询JS地图窗口小部件.我可以使用这个方法:
PyQt5.QtWebEngineWidgets.QWebEngineView().page().runJavaScript()
从加载的网页执行JS函数QWebEngineView()但是我在理解如何将一个由JS函数返回的值存储回python方面遇到了麻烦.
这里有一个完整的例子:
下面的PyQt5代码在PyQt4主窗口中加载一个pyqtwebtest.html带有leaflet.js地图窗口小部件的html page(),并添加一个按钮来执行JS代码,目的是将返回的值存储在python变量中...
#!/usr/local/bin/python36
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.form_widget = FormWidget(self)
_widget = QWidget()
_layout = QVBoxLayout(_widget)
_layout.addWidget(self.form_widget)
self.setCentralWidget(_widget)
class FormWidget(QWidget):
def __init__(self, parent):
super(FormWidget, self).__init__(parent)
self.__controls()
self.__layout()
def __controls(self):
self.browser = QWebEngineView()
self.browser.load(QUrl('file:///Users/epi/pyqtwebtest.html'))
def __layout(self):
self.vbox = QVBoxLayout()
self.hBox = QVBoxLayout()
self.getboundsbutton = QPushButton()
self.hBox.addWidget(self.browser)
self.hBox.addWidget(self.getboundsbutton)
self.vbox.addLayout(self.hBox)
self.setLayout(self.vbox)
self.getboundsbutton.clicked.connect(self.getBounds) …Run Code Online (Sandbox Code Playgroud) 我有一个使用 QWebChannel 创建谷歌地图实例的小部件。当在 javascript 中实例化 QWebChannel 时,会出现几个警告:
Property 'accessibleName'' of object 'MapWindow' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'accessibleDescription'' of object 'MapWindow' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'layoutDirection'' of object 'MapWindow' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'autoFillBackground'' of object 'MapWindow' has no notify signal and is not constant, …Run Code Online (Sandbox Code Playgroud)