Scott,

I’ve needed to address this issue before, myself. My solution was to subclass 
QPlainTextEdit and override QPlainTextEdit::keyPressEvent. In it, if 
QKeyEvent::key matches Qt::Key_Tab, I insert the desired number of spaces in 
place of a tab and accept the event (QEvent::accept).

If you don’t want to subclass QPlainTextEdit, I believe you should be able to 
create an object to install as an event filter on the editor. In it, you would 
compare the QEvent::type to QEvent::KeyPress and handle the logic in a similar 
fashion. That’s based on my limited Qt experience, so take that with a grain of 
salt.

I hope that helps.

Adam Thompson
Computer Scientist, Nuclear Engineering
Oak Ridge National Laboratory
+1.865.241.8062

From: Interest <interest-bounces+thompsonab=ornl....@qt-project.org> on behalf 
of Scott Aron Bloom <sc...@towel42.com>
Date: Friday, September 9, 2016 at 12:11 PM
To: "interest@qt-project.org" <interest@qt-project.org>
Subject: [Interest] QPlainTextEdit insert spaces vs tabs

I have a request that has come in from a customer, and for the life of me I 
cant find the option.

The customer would like to be able to insert spaces rather than tabs when 
editing a document, the editor has been implemented using QPlainTextEdit.

I can change the tabstop, and have looked through the QTextDocument options as 
well…

Any ideas?

Scott
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to