Results 1 to 3 of 3

Thread: QTextEdit and text interaction

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTextEdit and text interaction

    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:
    Qt Code:
    1. setReadOnly(true);
    2. setTextInteractionFlags(Qt::NoTextInteraction);
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit and text interaction

    You can use a label inside a scrollarea instead of QPlainTextEdit if it's an option for you.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit and text interaction

    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.

Similar Threads

  1. how to get the text from QTextEdit
    By qt_user in forum Qt Programming
    Replies: 5
    Last Post: 22nd August 2011, 00:22
  2. Replies: 4
    Last Post: 3rd June 2011, 10:35
  3. Replies: 1
    Last Post: 15th January 2009, 10:34
  4. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  5. entering text through user interaction in QTextEdit
    By sar_van81 in forum Qt Programming
    Replies: 6
    Last Post: 1st December 2006, 22:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.