Cancel update of text of QPlainTextEdit if terms not satisfied - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Cancel update of text of QPlainTextEdit if terms not satisfied (/thread-3452.html) |
Cancel update of text of QPlainTextEdit if terms not satisfied - panoss - May-24-2017 I have a QPlainTextEdit 's textChanged event connected to _criterion_txt_textChanged function. I want the user not to able to enter a value grater than 2 and smaller than 1. It can be int or decimal (float). When terms are not satisfied, I want to set it's text to '1'. (or maybe cancel update if possible) This is what I've done, but not working. def _criterion_txt_textChanged(self): if not re.match("\d*\.?\d*", criterion_txt.toPlainText()): msg = "Only integers and decimals allowed, from 1 up to 2" print(msg) criterion_txt.setPlainText("1") try: text = float(criterion_txt.toPlainText()) except: criterion_txt.setPlainText("1") msg = "Only integers and decimals allowed, from 1 up to 2" print(msg)How can I achieve this? |