0

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?

Tim Meyer
  • 12,210
  • 8
  • 64
  • 97
Babak Mehrabi
  • 2,155
  • 4
  • 23
  • 24
  • 2
    Why don't you just have 2 text edit's? one for input and one for output? You can then probably make the output text edit a read-only text edit as well. When you say "shell like" are you trying to create a command line like interface? – Viv Apr 11 '13 at 10:26
  • Yes. I want to create a command line like. Using two text edit is not my goal. I want my user enter commands and see the results – Babak Mehrabi Apr 11 '13 at 13:12

2 Answers2

2

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.

1

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.

cmannett85
  • 21,725
  • 8
  • 76
  • 119
  • In this way I must handle all things my self. Is there a high level solution? – Babak Mehrabi Apr 11 '13 at 13:13
  • @babak6 You have to reimplement a single method, save off the key presses, and monitor for 'Enter'. Everything else you were going to have to do anyway. – cmannett85 Apr 11 '13 at 13:32