[Interest] QPlainTextEdit insert spaces vs tabs

Scott Aron Bloom scott at towel42.com
Sat Sep 10 16:46:55 CEST 2016


Thanks!

I already had the derived class, so the extension was easy…

Scott

From: Interest [mailto:interest-bounces+scott=towel42.com at qt-project.org] On Behalf Of Thompson, Adam B.
Sent: Saturday, September 10, 2016 7:44 AM
To: interest at qt-project.org
Subject: Re: [Interest] QPlainTextEdit insert spaces vs tabs

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.gov at qt-project.org<mailto:interest-bounces+thompsonab=ornl.gov at qt-project.org>> on behalf of Scott Aron Bloom <scott at towel42.com<mailto:scott at towel42.com>>
Date: Friday, September 9, 2016 at 12:11 PM
To: "interest at qt-project.org<mailto:interest at qt-project.org>" <interest at qt-project.org<mailto:interest at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160910/47ea0771/attachment.html>


More information about the Interest mailing list