qt - QWebEngineView, post KeyEvents inside the View -


i have own "virtual keyboard". got transform buttons clicked keyevents , deliver qtextedit , on. problem want same writable areas inside qwebengineview.

for example, use keyboard edit qlineedit, , request website. done

let's requested google. have google website right in front of me. need send keyevents keyboard it's search box.(box inside qwebengineview.

let's point few points:

  1. i using pyqt5
  2. as i've read, api says me it's parent should consume keyevent corect place. here
  3. this snippet says "...like possible qtwebkit."
  4. i've seen there no more qtwebkit, , chromium instead.(maybe that's reason i'm not getting post these events)

this have example simulate keyevents qedittext , whatever..

from pyqt5.qtcore import qcoreapplication pyqt5.qtcore import qevent pyqt5.qtcore import qsize pyqt5.qtcore import qt pyqt5.qtgui import qicon pyqt5.qtgui import qkeyevent pyqt5.qtgui import qpixmap pyqt5.qtwidgets import qpushbutton   class keyboardkey(qpushbutton):      __path = ""      __size = [30, 30]     __style = ""     __icon_on = ""     __icon_off = ""     __auto_repeat = true     __receiver = none     __key = none     __str_key = none      def __init__(self, style, str_icon_on, str_icon_off, auto_repeat, size, receiver, key, str_key):         super(keyboardkey, self).__init__()         self.__size = size         self.__style = style         self.__icon_on = str_icon_on         self.__icon_off = str_icon_off         self.__auto_repeat = auto_repeat         self.__receiver = receiver         self.__key = key         self.__str_key = str_key         self.set_up_button(style, str_icon_on, str_icon_off, auto_repeat, size, receiver, key, str_key)      def set_up_button(self, style, str_icon_on, str_icon_off, auto_repeat, size, receiver, key, str_key):         self.__size = size         self.__style = style         self.__icon_on = str_icon_on         self.__icon_off = str_icon_off         self.__auto_repeat = auto_repeat         self.__receiver = receiver         self.__key = key         self.__str_key = str_key         self.settext(str_key)          self.setfixedsize(size[0], size[1])         self.setstylesheet(style)         self.seticonsize(qsize(size[0], size[1]))         self.seticon(qicon(self.__path + str_icon_off + ".png"))         self.setautorepeat(auto_repeat)         pixmap = qpixmap(self.__path + str_icon_off + ".png")         self.setmask(pixmap.mask())         self.pressed.connect(self.key_pressed)         self.released.connect(self.key_released)      def set_receiver(self, receiver):         self.__receiver = receiver      def key_pressed(self):         self.setstylesheet("""                             border-width: 5px;                             border-color: rgb(37,43,52);                             color: white;                             background-color: rgb(0,187,255);                         """,)      def key_released(self):         event = qkeyevent(qevent.keypress, qt.key_a, qt.nomodifier,                           "a", false)         # self.__receiver qedittext/qlineedit/...         self.__receiver.keypressevent(event) 

this last part 1 post events on "self.__receiver". receiver set "qwidget" invoke it.

i have tried like:

def key_released(self):     event = qkeyevent(qevent.keypress, qt.key_a, qt.nomodifier,                       "a", false)     # web_view qwebengineview... won't consume. or maybe it's not consuming right place.     self.web_view.keypressevent(event) 

this should work when send events qwebengineviews focusproxy instead - should work:

recipient = self.web_view.focusproxy() qapplication.postevent(recipient, event) 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -