I am experiencing strange behavior when embedding Qt-based plugins into web pages rendered using QtWebKit.<div><br></div><div>The plugins have child widgets accessible using the tab key, e.g. QLineEdit widgets. When there are no tab-accessible elements on the page, it only takes one keystroke of the tab key to move to the next field. However, if you begin adding tab-accessible elements to the page, you have to press the tab key as many more times as there are those elements in order to switch fields.</div>
<div><br></div><div>For example, the code posted below exhibits this behavior:</div><div><br></div><div>- startup: QLineEdit line1 has keyboard focus</div><div>- tab: does nothing</div><div>- tab: does nothing</div><div>
- tab: does nothing</div><div>- tab: moves keyboard focus to QLineEdit line2</div><div><div>- tab: does nothing</div><div>- tab: does nothing</div><div>- tab: does nothing</div><div>- tab: moves keyboard focus to QLineEdit line3</div>
<div><div>- tab: does nothing</div><div>- tab: does nothing</div><div>- tab: does nothing</div><div>- tab: nothing has keyboard focus</div><div>- tab: "somewhere" anchor in HTML has keyboard focus</div><div>
- tab: "somewhere else" anchor has keyboard focus</div><div>- tab: "hi" submit button has keyboard focus</div><div>- tab: QLineEdit line1 once again has keyboard focus</div><div><br></div><div>If you change the code to add more items in HTML that can get keyboard focus, you'll find that the length of the series of "tab does nothing" mentioned above is equal to the number of items in the HTML page that can get keyboard focus!</div>
<div><br></div></div></div><div><br></div><div>Is this an issue others have run into? I've only created a PyQt version, and not a C++ version, so I don't know if this is behavior that is due to PyQt or if it's something deeper within Qt and QtWebKit.</div>
<div><div><div><br></div><div><br></div><div><br></div><div>Configurations exhibiting this problem:</div><div><br></div><div>- Windows XP SP2</div><div> - Python 2.6.5</div><div> - PyQt 4.7</div><div> - Qt 4.6.1 (also has problem in Qt 4.5 and PyQt 4.6 series)</div>
<div><br></div><div>- Ubuntu 10.4 beta 2</div><div> - Python 2.6.5</div><div> - PyQt 4.7.2</div><div> - Qt 4.6.2</div><div><br></div><div><br></div><div><div><br></div><div>import sys</div><div><br></div><div>from PyQt4 import QtCore, QtGui, QtWebKit</div>
<div><br></div><div><br></div><div>HTML = """</div><div><html></div><div> <head></div><div> <title>QtWebKit Plug-in Test</title></div><div> </head></div><div> <body></div>
<div> <object type="application/x-qt-plugin" classid="MyCalendarWidget" name="lineedits" height=300 width=500></object></div><div> <script></div><div> lineedits.setLine1('line1');</div>
<div> lineedits.setLine2('line2');</div><div> lineedits.setLine3('line3');</div><div> </script></div><div> <br /></div><div> <a href="/">Somewhere</a></div>
<div> <a href="/foo">Somewhere else</a></div><div> <input type="submit" value="hello world" /></div><div> </body></div><div></html></div><div>"""</div>
<div><br></div><div><br></div><div>class MyWebView(QtWebKit.QWebView):</div><div><br></div><div> def __init__(self, parent=None):</div><div> super(MyWebView, self).__init__(parent)</div><div> self._page = MyWebPage(self)</div>
<div> self.setPage(self._page)</div><div><br></div><div><br></div><div>class MyWebPage(QtWebKit.QWebPage):</div><div><br></div><div> def __init__(self, parent=None):</div><div> super(MyWebPage, self).__init__(parent)</div>
<div> self.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled, True)</div><div><br></div><div> def createPlugin(self, classid, url, paramNames, paramValues):</div><div> return LineEditsWidget(self.view())</div>
<div><br></div><div><br></div><div>class LineEditsWidget(QtGui.QWidget):</div><div><br></div><div> def __init__(self, parent=None):</div><div> super(LineEditsWidget, self).__init__(parent)</div><div> self._layout = QtGui.QVBoxLayout(self)</div>
<div> self.setLayout(self._layout)</div><div> self.line1 = QtGui.QLineEdit(self)</div><div> self.line2 = QtGui.QLineEdit(self)</div><div> self.line3 = QtGui.QLineEdit(self)</div><div> self._layout.addWidget(self.line1)</div>
<div> self._layout.addWidget(self.line2)</div><div> self._layout.addWidget(self.line3)</div><div><br></div><div> @QtCore.pyqtSlot(str)</div><div> def setLine1(self, s):</div><div> self.line1.setText(s)</div>
<div><br></div><div> @QtCore.pyqtSlot(str)</div><div> def setLine2(self, s):</div><div> self.line2.setText(s)</div><div><br></div><div> @QtCore.pyqtSlot(str)</div><div> def setLine3(self, s):</div><div>
self.line3.setText(s)</div><div><br></div><div><br></div><div>app = QtGui.QApplication(sys.argv)</div><div><br></div><div>viewer = MyWebView()</div><div>viewer.setHtml(HTML)</div><div>viewer.show()</div><div><br></div>
<div>app.exec_()</div><div><br></div></div><div><br></div><div><br></div><div>-- <br>Matthew Scott<br><br>
</div></div></div>