[PyQt] QWebView in QGraphicsScene - drag and drop issue

Tom Batkiewicz tom.batkiewicz at priority5.com
Mon Apr 6 20:09:01 BST 2009


Hello all,

I get a hard crash with the following code if you drag/drop inside a 
QWebView that is being rendered inside of a QGraphicsScene.
The trick is that it functions properly if you use addWidget() to 
directly put the widget into the scene, but if you create the proxy 
yourself and call setWidget() before adding the proxy to the scene you 
get the crash.

----
import sys, os
from PyQt4 import QtGui, QtCore, QtWebKit, QtOpenGL

def main():
   app = QtGui.QApplication(sys.argv)
   browser = QtWebKit.QWebView()
   view = QtGui.QGraphicsView()
   view.setViewport(QtOpenGL.QGLWidget())
   scene = QtGui.QGraphicsScene()
   view.setScene(scene)
   browser.setUrl(QtCore.QUrl('http://www.google.com'))
  
   ## This fails
   proxy = QtGui.QGraphicsProxyWidget(None, QtCore.Qt.Widget)
   proxy.setWidget(browser)
   scene.addItem(proxy)
  
   ## This works
   #proxy = scene.addWidget(browser)  
  
   view.show()
  
   app.exec_()
  
   sys.exit()

if __name__ == '__main__':
   main()
----

I wrote some duplicate code in C++ to test Qt directly but that code 
functioned without error (both code paths) hence I'm here.
To duplicate, after running, click and drag the main google image or 
some text (any website or html will generate it as far as I can tell) 
and you should crash.
If you switch the comments to remove the manually created proxy section 
and instead use addWidget() it should eliminate the crash.

Subclassing QGraphicsProxyWidget is something I need to do so the 
addWidget() approach isn't going to work for me.
If someone can duplicate this or point out what I'm doing wrong I'd 
appreciate it. Thanks!

- Tom


More information about the PyQt mailing list