How do I access the variable x, which is the length of the input characters of an html input field, into the mousePressEvent function? And the variable x is a dynamic variable that increases with the length of each character. I want to control the text input dimensions inside the mousePressEvent. But I can not access the variable x.
import sys
import os
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets,
QtWebChannel
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.x = 50
self.setGeometry(300, 200, 800, 600)
self.channel = QtWebChannel.QWebChannel(self)
self.channel.registerObject("backend", self)
self.show()
@QtCore.pyqtSlot(str)
def pyFun1(self, x):
self.x = x
print(self.x)
def mousePressEvent(self, e):
self.view = QtWebEngineWidgets.QWebEngineView(self)
self.view.resize(self.x, 40)
self.view.page().setWebChannel(self.channel)
self.view.load(QtCore.QUrl().fromLocalFile(
os.path.split(os.path.abspath(__file__))
[0]+r'\index.html'))
self.view.move(QPoint(e.x(), e.y()))
self.view.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())