Search code examples
c++qtshellqtexteditqtscript

How to emulate a shell-like scripting environment with QTextEdit?


[Goal]

A simple shell prompt with QTextEdit, or any other appropriate Qt ways.

(Using QScriptEngine as an ECMA script interpreter is assumed)


[Example]

MATLAB

enter image description here

Python

enter image description here

In a shell prompt, the command line part is editable while the other parts are not. For MATLAB, only the line after the last >> is editable; for Python shell, only the line after the last >>> is editable.


[Workaround]

This is the first idea appear in my mind:

enter image description here

Using QTextEdit as read-only and QLineEdit as a command entry. For the purpose of pure functionality, it's acceptable, but not good enough.

[Question]

Actually the same question could be found here: Implementing a GUI Shell in qt, and the accepted answer is just the same as this workaround. Just like I said, the workaround is not good enough. I am wondering if it's possible to emulate a shell prompt with Qt? Currently, QTextEdit seems to be the best class to start.

Any ideas are welcome. Codes are welcome too but not needed, all I need are just some hints and directions.


Solution

  • You can take a look at QConsole which is a custom widget that implements a basic console and inherits from QTextEdit.