View Full Version : QTextEdit and text interaction

1st February 2013, 13:50

My app uses a QPlainTextEdit-derived widget to display some data. The user should be unable to interact with the data in any way.

Currently, in my widget's constructor, I have the following:


This seems to restrict most interactions. However, if the widget has focus, it is still possible to use Ctrl+A to select all the data, then Ctrl+C to copy it to the clipboard.

Is this a bug, or normal behavior? (I use Qt 4.6 btw.)

More importantly, what is the best way to prevent this? The only thing I can think of is writing my own event filter, but that seems a bit overkill/brute-force for what I'm trying to accomplish.

Thanks in advance.

1st February 2013, 17:59
You can use a label inside a scrollarea instead of QPlainTextEdit if it's an option for you.

4th February 2013, 17:24
Thanks for your reply. Since I use some QPlainTextEdit's facilities such as QPlainTextEdit::setExtraSelections() to display some information, using a label is not an option for me.

I ended up writing a simple "key press eater" event filter to disable Ctrl+A and Ctrl+C.

I'm still curious as to whether allowing Ctrl+A and Ctrl+C even when setTextInteraction(Qt::NoTextInteraction) has been called is intentional or not.