I
I
Imbolc2011-06-30 15:39:13
Python
Imbolc, 2011-06-30 15:39:13

Pyqt intercept shift-tab?

Ctrl-tab is intercepted normally, but there are some problems with shift-tab:

# -*- coding: utf-8 -*-<br>
from PyQt4 import QtCore, QtGui<br>
<br>
class MyTextEdit(QtGui.QTextEdit):<br>
    def __init__(self, parent):<br>
        QtGui.QTextEdit.__init__(self, parent)<br>
        <br>
    def keyPressEvent(self, event):<br>
        if event.key() == QtCore.Qt.Key_Tab:<br>
            if event.modifiers() == QtCore.Qt.ShiftModifier:<br>
                assert 0, 'shift-tab'<br>
            elif event.modifiers() == QtCore.Qt.ControlModifier:<br>
                assert 0, 'ctrl-tab'<br>
        super(MyTextEdit, self).keyPressEvent(event)<br>
<br>
class MainWindow(QtGui.QMainWindow):<br>
  def __init__(self):<br>
    super(MainWindow, self).__init__()<br>
    self.widget = MyTextEdit(self)<br>
    self.setCentralWidget(self.widget)<br>
<br>
if __name__ == '__main__':<br>
    import sys<br>
    app = QtGui.QApplication(sys.argv)<br>
    mainWindow = MainWindow()<br>
    mainWindow.show()<br>
    sys.exit(app.exec_())<br>
<br>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2011-06-30
@Imbolc

QtCore.Qt.Key_Backtab

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question