[PyQt] PyQt event management

Pierre Barthelemy barthpi at gmail.com
Mon Apr 16 17:30:07 BST 2012

Dear all,

I defined a few plot classes, children of qwidget, to handle chaco plots. I
would like to have a way to connect a few functions to the event of
clicking inside the window that i create. I have tried to implement a few
events. In this class, the close event works well. But the other don't:
when i click inside the qwidget, nothing happens. I would guess that it
come from the fact that the chaco plot items take the focus, so that when i
click inside the window, the chaco plot gets the event. Is there a way for
me to have these events activated, even if the mouse click also activates
events from the chaco plots ?

from PyQt4 import QtGui
from enthought.enable.qt4.image import Window
from enthought.chaco.toolbar_plot import ToolbarPlot

class LinePlot(QtGui.QWidget):
    def __init__(self, parent, title, x, y, xtitle, ytitle, type="line",
        # Create the subclass's window
        self.enable_win = self._create_window(title, x, y, xtitle, ytitle,
type, color,comment)
        layout = QtGui.QVBoxLayout()

    def _create_window(self, title):
        self._plotname = title
        self.plotdata = ArrayPlotData(x=x, y=y)
        plot = ToolbarPlot(self.plotdata, hiding=False, auto_hide=False)
        plot.plot(('x', 'y'), type=type, color=color)
        plot.title = title
        self.plot = plot
        return Window(self, -1, component=self.plot)

    def closeEvent(self,event):
        print 'CLOSE'
    def mouseReleaseEvent(self,event):
        print 'RELEASE'
    def mousePressEvent(self,event):
        print 'PRESS'
    def focusInEvent(self,event):
        print 'FOCUS'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120416/911f80c3/attachment.html>

More information about the PyQt mailing list