Babak Mehrabi
Babak Mehrabi

Reputation: 2275

Implementing a GUI Shell in qt

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?

Upvotes: 0

Views: 1360

Answers (2)

user362638
user362638

Reputation:

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.

Upvotes: 2

cmannett85
cmannett85

Reputation: 22346

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.

Upvotes: 1

Related Questions