[PyKDE] Make '/keyPressEvent' listening?

David Boddie david at boddie.org.uk
Wed Oct 11 14:38:07 BST 2006


On Wed Oct 11 13:15:10 MEST 2006, Andreas Pakulat wrote:
  
> On 11.10.06 12:21:28, Johannes Graumann wrote:
> > This pyqt4 documentation is driving me crazy ... took me forever to get
> > the 'ctrl_q' part right, but now I fail to figure out how to make my
> > 'self.maindialog' actually listening to it ... preciously few examples
> > for this on the web, so learning turns out to be hard work.
> 
> Have a look at PyQt4 examples, there are pretty many there.

They might not be all that easy to understand on their own, particularly
if you come to them with certain preconceptions about how they should work.

> > from PyQt4 import QtGui, QtCore
> > ctrl_q = QtGui.QKeyEvent(QtCore.QEvent.KeyPress,
> >                          QtCore.Qt.Key_Q,
> >                          QtCore.Qt.ControlModifier)
> > if self.maindialog.keyPressEvent(ctrl_q):
> >   _slot_Quit_Ctrl_Q
> 
> Ok, stop right here. Throw away all code you have. Read and understand
> the examples that come with PyQt4 and get a good book on Python/OO
> programming. You're clearly lacking OO programming skills and Qt is
> OO-only so you need them.

You might at least suggest a good book, Andreas. :-/

I don't know if Johannes is familiar with event-driven libraries, such as
PyGame, in which you retain control over the flow of execution and
periodically ask the library for events, such as those for user input.

However, with PyQt (and other frameworks) it's important to realise that you
give up control when the application's exec_() method is called, and
typically only respond to events from then on. This means that you may need
to perform certain tasks before calling exec_() or arrange for a way for them
to be called later on.

Some basic introductory material about PyQt4 is available in the slides for
a talk given at EuroPython 2006:

http://indico.cern.ch/contributionDisplay.py?contribId=33&sessionId=41&confId=44

Note that it wasn't aimed as an introduction to people starting out with
PyQt, but as a general overview of the features in PyQt4.

David




More information about the PyQt mailing list