Results 1 to 4 of 4

Thread: QTextEdit: prevent the insertion of some character.

  1. #1
    Join Date
    Sep 2010
    Posts
    45
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTextEdit: prevent the insertion of some character.

    It's possible to prevent the insertion of some specific character in the QTextEdit widget?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit: prevent the insertion of some character.

    have a look at QValidator
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTextEdit: prevent the insertion of some character.

    As far as I know QValidator is best used with a line edit. For a text edit you have to catch the key press events and filter there. An easy solution is not available. Only if you dealing with small text you can use the text changed signal and perform replace/remove instructions on the whole text.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit: prevent the insertion of some character.

    Sorry, for some reason my brain interpreted QTextEdit as QLineEdit.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 10
    Last Post: 17th July 2014, 10:52
  2. QTextEdit End-of-Line character
    By smhall316 in forum Newbie
    Replies: 1
    Last Post: 29th September 2010, 18:28
  3. How to get current character from QTextEdit
    By iamjayanth in forum Qt Programming
    Replies: 2
    Last Post: 6th April 2009, 08:05
  4. QTextEdit and Form Feed character
    By gvlaovic in forum Qt Programming
    Replies: 1
    Last Post: 15th September 2007, 12:37
  5. Finidng the pixels for a character in QTextEdit
    By sukanyarn in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2006, 09:56

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.