Results 1 to 5 of 5

Thread: [PyQt4] Trouble with event handling

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [PyQt4] Trouble with event handling

    I am connecting widgets with event handlers in PyQt and trying to find the widget that was used. I learned to do this in wxPython:
    Qt Code:
    1. button1 = wx.Button(self, -1, "Button 1")
    2. button2 = wx.Button(self, -1, "Button 2")
    3. button3 = wx.Button(self, -1, "Button 3")
    4.  
    5. button_group = (button1, button2, button3)
    6.  
    7. for entry in button_group:
    8. entry.Bind(wx.EVT_BUTTON, self.onButton)
    9.  
    10.  
    11. def onButton(self, event):
    12. eventVal = event.GetEventObject()
    13. labelVal = eventVal.GetLabel()
    14.  
    15. print "%s pressed" % labelVal
    To copy to clipboard, switch view to plain text mode 
    But I am having trouble figuring out how to do this with PyQt. This is the only way that I know how to catch events:
    Qt Code:
    1. button1 = QtGui.QPushButton("Button 1")
    2. button2 = QtGui.QPushButton("Button 2")
    3. button3 = QtGui.QPushButton("Button 3")
    4.  
    5. button_group = [button1, button2, button3]
    6.  
    7. for entry in button_group:
    8. self.connect(entry, QtCore.SIGNAL('clicked()'), self.onButton)
    9.  
    10.  
    11. def onButton(self):
    12. """
    13. I do not know what to put here.
    14. """
    15. pass
    To copy to clipboard, switch view to plain text mode 
    Last edited by Dodle; 4th May 2009 at 06:23.

Similar Threads

  1. Replies: 4
    Last Post: 19th February 2009, 11:10
  2. Key Press Event trouble
    By morraine in forum Newbie
    Replies: 6
    Last Post: 18th August 2008, 08:43
  3. Handling mouse over event for QListWidget
    By Abc in forum Qt Programming
    Replies: 2
    Last Post: 22nd July 2008, 18:32
  4. event handling...
    By xyzt in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2008, 07:16
  5. QGraphicsView Handling Child Event
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2007, 00:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.