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 .
Re: QTextEdit accept only "OK/KO" in Pyside2
everything in here was nonsense. Should read question before answering...
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
Re: QTextEdit accept only "OK/KO" in Pyside2
Quote:
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.
Quote:
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.