4

I am writing a small editor. I would like to change default behaviour of QTextEdit, that inserts tabs when Tab is hit. Instead I would like to put 4 spaces. What is the recommended way of doing this? I though about subclassing keyPressedEvent, but maybe there is some better way?

gruszczy
  • 40,948
  • 31
  • 128
  • 181

1 Answers1

5

My opinion is that subclassing and overriding the keyPressEvent function is the way to go. If for whatever reason you are really adverse to subclassing you could probably use an event filter (see QObject::installEventFilter() and QObject::eventFilter()).

Chris
  • 17,119
  • 5
  • 57
  • 60
  • I would agree. If you just wanted to know about the key press (for initiating some other activity in the app) then an event filter would be the way to go. But if you want to actually modify the behavior of the QTextEdit, then that should be encapsulated in a subclass. – Arnold Spence Jul 26 '11 at 16:01