Answer the question
In order to leave comments, you need to log in
PyQT browser and embedded inside yandex iframe. How to "fix" button inside iframe for accepting payments?
After clicking on the "Pay" button, nothing happens. The button doesn't seem to work.
It is necessary to make it so that after clicking on the "Pay" button, it will be transferred to the default browser in the OS for the final payment.
I added a test link to the code next to it. Everything works with her. The link opens in the OS browser. But with a button, no.
In total, it has already taken me 6 hours to try to create all possible crutches. :(.
It doesn’t even matter to me which version the example will be on - on pyqt4 or pyqt5. Just to see the light at the end of the tunnel.
I give the code both on PyQt5 and on PyQt4 after.
Code on PyQt5:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import webbrowser
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
class MainWindow(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.resize(700, 400)
self.view = QWebEngineView()
s = str("""<!DOCTYPE html>
<html>
<head></head>
<div style="text-align: center;">
<iframe frameborder="0" allowtransparency="true" scrolling="no" src="https://money.yandex.ru/quickpay/shop-widget?account=410013878567203&quickpay=shop&payment-type-choice=on&mobile-payment-type-choice=on&writer=seller&targets=asdf&targets-hint=&default-sum=&button-text=01&successURL="" width="450" height="200"></iframe>
</div>
<div>
<a href="http://google.com">TEST LINK</a>
</div>
</body>
</html>""")
self.view.setHtml(s)
self.view.urlChanged['QUrl'].connect(self.linkClicked)
grid = QGridLayout()
grid.addWidget(self.view, 0, 0)
self.setLayout(grid)
def linkClicked(self, url):
print(url.toString())
webbrowser.open(url.toString())
if __name__ == '__main__':
app = None
if not QApplication.instance():
app = QApplication([])
dlg = MainWindow()
dlg.show()
if app: app.exec_()
#!/usr/bin/python
# -*- coding: utf-8 -*-
import webbrowser
from PyQt4 import QtCore, QtGui, QtWebKit
from PyQt4.QtCore import QUrl
from PyQt4.QtWebKit import *
class MainWindow(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.resize(700, 400)
self.view = QtWebKit.QWebView()
s = str("""<!DOCTYPE html>
<html>
<head></head>
<div style="text-align: center;">
<iframe frameborder="0" allowtransparency="true" scrolling="no" src="https://money.yandex.ru/quickpay/shop-widget?account=410013878567203&quickpay=shop&payment-type-choice=on&mobile-payment-type-choice=on&writer=seller&targets=asdf&targets-hint=&default-sum=&button-text=01&successURL="" width="450" height="200"></iframe>
</div>
<div>
<a href="http://google.com">TEST LINK</a>
</div>
</body>
</html>""")
self.view.setHtml(s)
self.view.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
self.view.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateExternalLinks)
self.connect(self.view, QtCore.SIGNAL("linkClicked(const QUrl)"), self.linkClicked)
grid = QtGui.QGridLayout()
grid.addWidget(self.view, 0, 0)
self.setLayout(grid)
def linkClicked(self, url):
print(url.toString())
webbrowser.open(url.toString())
if __name__ == '__main__':
app = None
if not QtGui.QApplication.instance():
app = QtGui.QApplication([])
dlg = MainWindow()
dlg.show()
if app: app.exec_()
Answer the question
In order to leave comments, you need to log in
This option works on pyqt5. Checked.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import webbrowser
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
s = str("""<!DOCTYPE html>
<html>
<head></head>
<div style="text-align: center;">
<iframe frameborder="0" allowtransparency="true" scrolling="no" src="https://money.yandex.ru/quickpay/shop-widget?account=410013878567203&quickpay=shop&payment-type-choice=on&mobile-payment-type-choice=on&writer=seller&targets=asdf&targets-hint=&default-sum=&button-text=01&successURL="" width="450" height="200"></iframe>
</div>
<div>
<a href="http://google.com">TEST LINK</a>
</div>
</body>
</html>""")
class MainWindow(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.resize(700, 400)
self.view = QWebEngineView(self)
mypage = MyPage(self.view)
self.view.setPage(mypage)
mypage.setHtml(s)
grid = QGridLayout()
grid.addWidget(self.view, 0, 0)
self.setLayout(grid)
self.show()
class MyPage(QWebEnginePage):
def __init__(self, parent):
super().__init__(parent)
self.in_window = False # придумал переменную
def createWindow(self, type): # которую мы
self.in_window = True # тутже изменяем если просится
return self # открытие в новом окне
def acceptNavigationRequest(self, QUrl, type, isMainFrame):
url_string = QUrl.toString()
print(type, isMainFrame, QUrl)
if self.in_window and type==2 and url_string != "https://money.yandex.ru/quickpay/confirm.xml":
webbrowser.open(url_string)
self.in_window = False
self.setHtml(s)
return True
if __name__ == '__main__':
app = None
if not QApplication.instance():
app = QApplication([])
dlg = MainWindow()
if app: app.exec_()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question