Question

I want to implement a simple graphical shell in Qt using a QTextEdit. I want to get user commands and print the results in that QTextEdit.

The code below returns the whole content of the QTextEdit:

text_editor.toPlainText().toAscii();

But I don't know how to differentiate between what the user entered and what was printed before. What is the right way to do this?

Was it helpful?

Solution

Use QTextEdit for output. It supports multiple lines and you can control colors using HTML. Then use single line QLineEdit for entering commands. Place the QLineEdit under the QTextEdit and there you have a GUI for a simple command interface! When you enter a command to the QLineEdit, print it to the QTextEdit too, perhaps using different color than the results of the command.

This is much easier than trying to do everything with one widget.

OTHER TIPS

Reimplement the key press event handler to do it's normal work, but also to save the user typed data. Once enter is pressed, the separately saved text is executed and then cleared.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top