Results 1 to 5 of 5

Thread: validate QPlainTextEdit text

  1. #1
    Join Date
    May 2014
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1

    Default validate QPlainTextEdit text

    I want to validate QPlainTextEdit text whenever user clicks on somewhere else in the GUI e.g., toolbar or menubar. QFocusOutEvent is not helpful because lets say I click on toolbar button then first the slot connected to toolbar button is activated and then QFocusOutEvent is triggered. How do I make sure I get it first so I can validate and then proceed with toolbar action.

    Adeel.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: validate QPlainTextEdit text

    You can connect a slot to the QPlainTextEdit::textChanged() signal or to the QTextDocument::contentsChanged() signal. These might be emitted on a character-by-character basis, but they look like the only way you can do validation. Unless you disable the rest of the GUI when the content is not valid, you can't really prevent the user from clicking elsewhere.

  3. #3
    Join Date
    May 2014
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1

    Default Re: validate QPlainTextEdit text

    As you already said "these might be emitted on a character-by-character basis" so this means I am most of the time reporting error to users because the text will be incomplete and of course invalid.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: validate QPlainTextEdit text

    text will be incomplete and of course invalid
    In which case your validation needs to recognize that partial text is also valid. You might be able to use QValidator for this because it does have a model for "intermediate" validation.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: validate QPlainTextEdit text

    Another option would be to not assume that the content is valid when you perform an action on it, but to explicitly verify it.

    E.g. if you have a toolbar action that copies the content into the clipboard, make it first check if that is allowed.

    Like doing a final check in a dialog when OK is clicked, or on a web form when it is submitted.

    Cheers,
    _

Similar Threads

  1. QPlainTextEdit text alignment
    By mkh in forum Qt Programming
    Replies: 2
    Last Post: 30th July 2013, 17:27
  2. multicolor text in QPlainTextEdit
    By mastupristi in forum Qt Programming
    Replies: 5
    Last Post: 14th January 2011, 22:37
  3. Selecting Text QPlainTextEdit
    By smhall316 in forum Newbie
    Replies: 0
    Last Post: 7th December 2010, 21:09
  4. read text from QPlainTextEdit
    By chs in forum Newbie
    Replies: 2
    Last Post: 21st November 2009, 13:07
  5. QPlainTextEdit reload text
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 25th April 2009, 15:24

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.