Skip to content

Instantly share code, notes, and snippets.

@minrk
Created November 1, 2011 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minrk/1331650 to your computer and use it in GitHub Desktop.
Save minrk/1331650 to your computer and use it in GitHub Desktop.
"""Test case for PySide bug #982
If you hover the mouse over the window, it will be fine,
but the first time the topLevelAt is called with the cursor
outside the window, it will segfault.
"""
# stdlib imports
import sys
# Import Qt:
from PySide import QtGui, QtCore
# from PyQt4 import QtGui, QtCore
def print_topLevelAt():
"""callback to print current cursor position and return of topLevelAt"""
cpos = QtGui.QCursor.pos()
print cpos
# when nothing is there, PyQt returns None
# whereas PySide segfaults in this call:
print QtGui.qApp.topLevelAt(cpos)
if __name__ == '__main__':
# create empty window, with a timer that calls topLevelAt with
# the current cursor position every 1s
app = QtGui.QApplication([])
window = QtGui.QMainWindow()
window.show()
timer = QtCore.QTimer()
timer.timeout.connect(print_topLevelAt)
timer.start(1000)
app.exec_()
@minrk
Copy link
Author

minrk commented Nov 1, 2011

definitely affect pyside-1.0.6 on OSX, and appears to be fixed in pyside-1.0.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment