Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

PyQt5 change keyboard/tab behaviour in a table

from PyQt5 import QtCore, QtGui, QtWidgets

class Helper(QtCore.QObject):
    def __init__(self, parent=None):
        super(Helper, self).__init__(parent)
        self.m_widgets = []

    def appendWidget(self, widget):
        self.m_widgets.append(widget)
        widget.installEventFilter(self)

    def eventFilter(self, obj, event):
        if obj in self.m_widgets and event.type() == QtCore.QEvent.KeyPress:
            if event.key() == QtCore.Qt.Key_Tab:
                # create new event
                new_event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, 
                    QtCore.Qt.Key_Down, 
                    QtCore.Qt.NoModifier)
                # send new event
                QtCore.QCoreApplication.postEvent(obj, new_event)
                # if True, the event is discarded
                return True
        return super(Helper, self).eventFilter(obj, event)


class Widget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(Widget, self).__init__(parent)
        self.table = QtWidgets.QTableWidget(4, 4)
        lay = QtWidgets.QVBoxLayout(self)
        lay.addWidget(self.table)

        helper = Helper(self)
        helper.appendWidget(self.table)


if __name__ == '__main__':
    import sys

    app = QtWidgets.QApplication(sys.argv)
    w = Widget()
    w.show()
    sys.exit(app.exec_())
Comment

PREVIOUS NEXT
Code Example
Python :: pytorch get intersection between two masks 
Python :: python with statement variables 
Python :: Make Latest pyhton as default in mac 
Python :: save csv with today date pandas 
Python :: expand array to a certain size python 
Python :: select nth item from list 
Python :: What is StringIndexer , VectorIndexer, and how to use them? 
Python :: limiting user input to under 100 characters python 
Python :: menampilkan data dalam range tertentu di python 
Python :: "DO_NOTHING" is not defined django 
Python :: django admin link column display links 
Python :: variable types in python 
Python :: how to code a discord bot in python nextcord 
Python :: python class private variables 
Python :: python geopandas read layer from gdb 
Python :: nlp generate parse tree in python 
Python :: unpad zeros from string python 
Python :: spark write progress bar jupyter 
Python :: ler arquivo xls no pandas 
Python :: python: dunder init method 
Python :: pyhton how to chnge colour of graphs 
Python :: bar chart with x-ticks 
Python :: get the hour of every instance of the date_time 
Python :: python fibonacci sequence while loop 
Python :: how to store svgs in django image field with SVGAndImageFormField 
Python :: django is .get lazy 
Python :: get element tag name beautfulsoup 
Python :: numpy transpose shorthand 
Python :: Saving a copy of rcParams settings. 
Python :: multiplication objects 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =