Results 1 to 4 of 4

Thread: Make QTextEdit accept only "OK/KO" in Pyside2

  1. #1
    Join Date
    Aug 2019
    Posts
    15
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Make QTextEdit accept only "OK/KO" in Pyside2

    I have designed an QTreeWidget with a QTextedit as one of the widget of the QTreeWidget. I am entering status value as "OK/KO" inside the QTextEdit. I want to restrict the input in the QTextEdit only to "OK/KO" and user should be prompted by message box to enter only this two values. I am really clueless how to proceed further with this .
    Last edited by supratik; 12th November 2020 at 09:10.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    460
    Thanks
    10
    Thanked 61 Times in 59 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit accept only "OK/KO" in Pyside2

    everything in here was nonsense. Should read question before answering...
    Last edited by Ginsengelf; 12th November 2020 at 07:25. Reason: updated contents

  3. #3
    Join Date
    Aug 2019
    Posts
    15
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTextEdit accept only "OK/KO" in Pyside2

    Can you explain what was nonsense? Maybe it was nonsense for you, but I am pretty new , that's why it is posted in newbie section of the forum
    Last edited by supratik; 12th November 2020 at 08:52.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,883
    Thanks
    274
    Thanked 794 Times in 784 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QTextEdit accept only "OK/KO" in Pyside2

    I have designed an QTreeWidget with a QTextedit as one of the widget of the QTreeWidget.
    First, maybe you can explain what you are doing here. How are you making "QTextEdit one of the widgets of QTreeWidget"? This doesn't make a lot of sense.

    I want to restrict the input in the QTextEdit only to "OK/KO" and user should be prompted by message box to enter only this two values.
    Second, if you are using QTextEdit just to edit a two-letter string, why? QLineEdit seems a better fit.

    And third, if you use QLineEdit, then you can either 1) use an input mask (QLineEdit::setInputMask()) that restricts them from entering anything except "K" or "O", 2) use a QCompleter that gives only "OK" or "KO" as choices, 3) use a QValidator that accepts only "OK" or "KO", or 4) write your own handlers for the QLineEdit::textChanged(), QLineEdit::textEdited(), or QLineEdit::editingFinished() signals where you check to see if the user is entering (or has entered) the correct characters and either accept them or display your error message.

    But to be honest, if the only thing the user can enter is "OK" or "KO" (whatever that means), then why don't you just use a check box? Either it is checked or it isn't, and that's your status.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. The following user says thank you to d_stranz for this useful post:

    supratik (18th November 2020)

Similar Threads

  1. Replies: 1
    Last Post: 20th November 2015, 10:02
  2. Linker does not accept overloaded "operator>>"
    By ZikO in forum Qt Programming
    Replies: 7
    Last Post: 31st August 2012, 23:33
  3. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  4. On MacOSX, QMessage don't accept "\n"
    By manhds in forum Qt Programming
    Replies: 7
    Last Post: 7th June 2006, 15:04

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