Implementing a GUI Shell in qt

余生颓废 提交于 2019-12-04 06:35:31

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/15945926/implementing-a-gui-shell-in-qt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!