PDA

View Full Version : QTextEdit and text interaction



joelafrite
1st February 2013, 12:50
Hello,

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:

setReadOnly(true);
setTextInteractionFlags(Qt::NoTextInteraction);

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.

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

joelafrite
4th February 2013, 16: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.