PDA

View Full Version : QTextEdit



RY
15th October 2008, 05:56
How would you output text dynamically to QTextEdit to be viewed by the user?

JimDaniel
15th October 2008, 07:01
What do you mean by dynamically?

RY
15th October 2008, 08:08
I mean that if you want to say solve an equation x = 4(6+5), you can stop the solution after solving 6+5 and display x = 4(11). Then continue and display x=44. This is not the actual type of equation that I'm trying to solve; however this is what I mean by "dynamic". The following is another example.

Suppose you input the equation x = 5 + 2(25 - 15/y), and you set y to 3...
I want the QTextEdit to EVENTUALLY display

x = 5 + 2(25 - 15/y)
x = 5 + 2(25 - 15/3)
x = 5 + 2(25 - 5)
x = 5 + 2(20)
x = 5 + 40
x = 45

I was also wondering on how you could incorporate a stop. In which the next step is displayed only if the user chooses to continue.

x = 5 + 2(25 - 15/y)
ask if continue

x = 5 + 2(25 - 15/3)
ask if continue

x = 5 + 2(25 - 5)
ask if continue

x = 5 + 2(20)
ask if continue

x = 5 + 40
ask if continue

x = 45

Does that make sense?

fullmetalcoder
15th October 2008, 13:01
Sounds like a task for a custom widget as QTextEdit would make it complicated to add the stop feature and bring unnecessary complexity (as you don't need to edit the text once written right?). A simple scroll area with a QStringList of lines to display should do. Then just add a string to the list to display a new line (and update display) and reimplement the keyPressEvent to add the "stop" feature.

RY
15th October 2008, 16:10
Correct, we don't need to edit the text once it is written.

It sounds like you know what I mean. Do you have some simple example code of your explanation? What classes and functions are you thinking of?

fullmetalcoder
15th October 2008, 18:52
I've basically rewritten QTextEdit from scratch (removing some features and adding new ones) in my QCodeEdit library and what I did was that : subclass QAbstractScrollArea and reimplement event handlers just like QTextEdit does. The same approach should do for you, except that it will be simpler as you do not need to handle much interaction.

I just wrote a quick example for educationnal purpose (and because I wanted to do something more entertaining than linear algebra assignements) : http://edyuk.org/misc/scrollingdisplay.tar.gz

It basically appends lines made of 30 random digits to a scrolling display, at a rate of one new line every 200ms (i.e 5 lines per seconds)

The example code is available under BSD license (i.e free to use for any purpose with (almost) no restrictions). Proper management of the horizontal scrollbar and further improvements are left as an exercise to the reader.