Python Forum
Cancel update of text of QPlainTextEdit if terms not satisfied
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cancel update of text of QPlainTextEdit if terms not satisfied
#1
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to update label text using a grid button. Edward_ 7 1,912 Dec-18-2024, 03:05 AM
Last Post: Edward_
  update text variable on label with keypress knoxvilles_joker 5 7,916 May-31-2024, 02:09 PM
Last Post: menator01
  [Tkinter] Make my button text update? Skata100 1 2,836 Aug-07-2021, 05:37 AM
Last Post: deanhystad
  [Tkinter] how to update label text from list Roshan 8 7,535 Apr-25-2020, 08:04 AM
Last Post: Roshan
  Update a label text from subprocess jim53 3 5,693 Aug-19-2019, 08:21 PM
Last Post: Denni
  Unable to update or refresh label text in tkinter jenkins43 3 8,822 Jul-24-2019, 02:09 PM
Last Post: Friend
  Update value selected in option menu when select an item from text box klllmmm 2 6,567 Jun-06-2019, 04:51 AM
Last Post: klllmmm
  Display and update the label text which display the serial value jenkins43 5 11,223 Feb-04-2019, 04:36 AM
Last Post: Larz60+
  [Tkinter] update the content of Text widget atlass218 10 19,224 Dec-15-2018, 11:51 AM
Last Post: atlass218

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020