[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] Segfaults on MacOS
From: Michael Held <michael.held () bc ! biol ! ethz ! ch>
Date: 2009-06-28 21:42:21
Message-ID: h28o3t$o3p$1 () ger ! gmane ! org
[Download RAW message or body]
hi,
I am building an image viewer with PyQt and wanted to display the pixel
color under the cursor for mouseMoveEvent - everything fine so far.
using the eventFilter I was able circumvent QLabel sub-classing.
*BUT* printing the pixel value crashes my program with a seg fault (I am
just moving a bit over the image and BANG...)
my silly attempt to delay the event-response with time.sleep(0.5) did
also not work.
I was using Stackless Python 2.6.2 before but the same error happened
for the normal Python 2.6.2
MacOS 10.5.7
PyQt-mac-gpl-4.5.2-snapshot-20090627
sip-4.8.1
thanks a lot!
michael
class ImageViewer(QScrollArea):
def __init__(self, parent):
super(ImageViewer, self).__init__(parent)
self.setBackgroundRole(QPalette.Dark)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.label = QLabel(self)
self.label.setBackgroundRole(QPalette.Base)
self.setAlignment(Qt.AlignHCenter|Qt.AlignVCenter)
self.label.installEventFilter(self)
self.label.show()
self.label.setMouseTracking(True)
self.setWidget(self.label)
self._qimage = None
self.connect(self, SIGNAL('MouseMovedOverImage'),
self._on_move)
def from_numpy(self, data):
self._qimage = numpy_to_qimage(data)
self._update()
def from_qimage(self, qimage):
self._qimage = qimage
self._update()
def _on_move(self, pos):
print pos, self._qimage.pixel(pos)
time.sleep(0.5)
def eventFilter(self, obj, ev):
if ev.type() == QEvent.MouseMove and obj == self.label:
self.emit(SIGNAL('MouseMovedOverImage'),
ev.pos())
return True
else:
return False
def _update(self):
self.label.setPixmap(QPixmap.fromImage(self._qimage))
self.label.resize(self.label.pixmap().size())
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic