Results 1 to 3 of 3

Thread: [pyqt]Event - catch only Qt.Key_Delete

  1. #1
    Join Date
    Apr 2011
    Posts
    3
    Qt products
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default [pyqt]Event - catch only Qt.Key_Delete

    Hello!

    I would like to change behavior of Key_Delete for QTableWidget, but because of using Designer I don't want to make any changes in py file with form. So instead of reimplementing QTableWidget, I do something like this:
    Qt Code:
    1. class MyForm(QtGui.QMainWindow):
    2. def __init__(self, parent=None):
    3. QtGui.QWidget.__init__(self, parent)
    4. self.ui = Ui_MainWindow()
    5. self.ui.setupUi(self)
    6.  
    7. self.ui.tableWidget.__class__.keyPressEvent = self.test
    8.  
    9. def test(self,event):
    10. if event.key() == Qt.Key_Delete:
    11. print "test"
    12.  
    13. return QTableWidget.keyPressEvent(self, event)
    To copy to clipboard, switch view to plain text mode 

    The problem is that I don't know how to keep original behavior of other keys than Qt.Key_Delete. I have already changed last line like this:

    Qt Code:
    1. return QtGui.QTableWidget.keyPressEvent(self, event)
    2. return QtGui.QTableWidget.event(self, event)
    To copy to clipboard, switch view to plain text mode 

    but it doesn't work.

  2. #2
    Join Date
    Aug 2015
    Posts
    1
    Qt products
    Platforms
    Windows

    Default Re: [pyqt]Event - catch only Qt.Key_Delete

    Qt Code:
    1. return QtGui.QTableWidget.keyPressEvent(self.ui.tableWidget, event)
    To copy to clipboard, switch view to plain text mode 
    Last edited by svarti; 26th August 2015 at 07:36.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: [pyqt]Event - catch only Qt.Key_Delete

    Or you could use an event filter, see QObject::eventFilter()

    Cheers,
    _

Similar Threads

  1. catch exit event
    By GrahamLabdon in forum Newbie
    Replies: 8
    Last Post: 18th December 2010, 14:47
  2. How to catch event, then objectName changed.
    By sergey_85 in forum Qt Programming
    Replies: 1
    Last Post: 25th April 2010, 20:05
  3. how to catch close event in this program? [pyqt]
    By pyqt123 in forum Qt Programming
    Replies: 15
    Last Post: 14th December 2009, 11:30
  4. Catch click Hyperlink event
    By summer_of_69 in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2009, 19:43
  5. Catch a row selection event in QTableView
    By Windsoarer in forum Qt Programming
    Replies: 1
    Last Post: 2nd March 2009, 22:44

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
  •  
Qt is a trademark of The Qt Company.