qtwebengine

how to print html page with image in Qprinter pyqt5

荒凉一梦 提交于 2020-03-16 07:04:48
问题 i have generated a report for my program using html code but it doesn't show image in Qprinter. def run(self): view = QtWebEngineWidgets.QWebEngineView() view.setHtml("""<img src="header.jpeg" alt="logo" width="280" height="100">""") printer = QPrinter() printer.setPaperSize(QtCore.QSizeF(80 ,297), QPrinter.Millimeter) try : r = QPrintDialog(printer) if r.exec_() == QPrintDialog.Accepted: view.page().print(printer, self.print_completed) except Exception as e : print(e) html code that i want

Qt Event Propagation in QWebEngineView

夙愿已清 提交于 2020-02-16 05:49:30
问题 I have a function named generate_input_event . I'm trying to use this function to simulate a keypress within a QWebEngineView. def generate_input_event(window_id, key_code, modifiers, low_level_data, x, y): modifiers_flag = create_modifiers_flag(modifiers) logging.info("generate input, window: {} code: {}, modifiers {}".format( window_id, key_code, modifiers_flag)) event = QKeyEvent(QEvent.KeyPress, key_code, modifiers_flag) event.artificial = True event_window = window.get_window(window_id)

Qt Event Propagation in QWebEngineView

天大地大妈咪最大 提交于 2020-02-16 05:48:03
问题 I have a function named generate_input_event . I'm trying to use this function to simulate a keypress within a QWebEngineView. def generate_input_event(window_id, key_code, modifiers, low_level_data, x, y): modifiers_flag = create_modifiers_flag(modifiers) logging.info("generate input, window: {} code: {}, modifiers {}".format( window_id, key_code, modifiers_flag)) event = QKeyEvent(QEvent.KeyPress, key_code, modifiers_flag) event.artificial = True event_window = window.get_window(window_id)

Taking a screenshot of a web page in PyQt5

走远了吗. 提交于 2020-01-30 06:41:25
问题 I would like to use PyQt5 to take a screenshot of a webpage. (A full webpage, including the stuff a user wouldn't see unless they scrolled down.) Supposedly, it is possible to do this in PyQt5 using QtWebEngine. How would you do it though? I specifically don't want the user to see a browser window opening or rendering. I just want a screenshot in a PNG file. 回答1: -This code was tested in : QT_VERSION_STR = 5.12.1 , PYQT_VERSION_STR = 5.12 NOTE: QtWebKit got deprecated upstream in Qt 5.5 and

Qt WebEngine simulate Mouse Event

女生的网名这么多〃 提交于 2020-01-20 09:00:49
问题 I want to simulate mouse Event in my Qt WebEngine app. I use PyQt5.8 , QT5.8 . This is my code: def mouse_click(self, x, y): point = QPoint(int(x), int(y)) eventp = QMouseEvent(QMouseEvent.MouseButtonPress,point,Qt.LeftButton,Qt.LeftButton,Qt.NoModifier) self.sendEvent(eventp) eventp = QMouseEvent(QMouseEvent.MouseButtonRelease,point,Qt.LeftButton,Qt.LeftButton,Qt.NoModifier) self.sendEvent(eventp) def sendEvent(self, event): recipient = self.webpage.view().focusProxy() recipient.grabKeyboard

Qt WebEngine simulate Mouse Event

南楼画角 提交于 2020-01-20 09:00:02
问题 I want to simulate mouse Event in my Qt WebEngine app. I use PyQt5.8 , QT5.8 . This is my code: def mouse_click(self, x, y): point = QPoint(int(x), int(y)) eventp = QMouseEvent(QMouseEvent.MouseButtonPress,point,Qt.LeftButton,Qt.LeftButton,Qt.NoModifier) self.sendEvent(eventp) eventp = QMouseEvent(QMouseEvent.MouseButtonRelease,point,Qt.LeftButton,Qt.LeftButton,Qt.NoModifier) self.sendEvent(eventp) def sendEvent(self, event): recipient = self.webpage.view().focusProxy() recipient.grabKeyboard

inject code to webpage using QWebEnginePage::runJavaScript()

为君一笑 提交于 2020-01-17 01:33:10
问题 When QWebEngineView starts loading a web page , I want to inject a web page progress bar to it, my code as the following , but I cannot see the progress bar during loading , so what's wrong ? import sys from PyQt5.QtWidgets import * from PyQt5.QtWebEngineWidgets import * from PyQt5.QtWebEngineCore import * from PyQt5.QtCore import * class WebEngineView(QWebEngineView): def __init__(self, parent=None): super().__init__(parent) self.webPage = self.page() self.webPage.runJavaScript(''' var

Qt Webengine Render to Print

痴心易碎 提交于 2020-01-03 11:50:33
问题 Is there any way to render HTML/SVG to printer, PDF, and raster images with QtWebEngine? We want to switch from WebKit to WebEngine, so using WebKit's QWebView is not an option anymore. 回答1: It is announced that Qt Web Engine will support printing to PDF in Qt 5.7 which is in beta now. Two overloads of printToPdf() function were added in Qt 5.7 for QWebEnginePage class. We have example how to use these new functions in our company blog. You can look for some already available Qt Web Engine

QWebEnginePage: toHtml returns an empty string

馋奶兔 提交于 2020-01-02 17:01:27
问题 I need to retrieve some html from a QWebEnginePage . I found in the documentation the method toHtml but it always returns an empty string. I tried toPlainText and it works, but this is not what I need. MyClass::MyClass(QObject *parent) : QObject(parent) { _wp = new QWebEnginePage(); _wp->settings()->setAttribute(QWebEngineSettings::AutoLoadImages, false); _wp->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true); connect(_wp, SIGNAL(loadFinished(bool)), this, SLOT

How to get the contentSize of a web page in Qt5.4-QtWebEngine

梦想与她 提交于 2020-01-02 12:48:07
问题 I'm using the new Qt5.4 with the module QtWebEngine and from what I see mainFrame() doesn't exists anymore. How to get the contentSize/size of the page and how to render it now? I tried with the setView and view but doesn't work. 回答1: Check if the QWebEnginePage::geometryChangeRequested signal does what you want. Also you display a QWebEnginePage by creating a QWebEngineView (it's a QWidget ) and calling QWebEngineView::setPage(yourPage) . 回答2: I couldn't find any native Qt method for that,