Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Emulating command console
I want it to be like the windows cmd, you write a command and then it gives back information but you cant edit what already is writed, you can only edit the text that you are introducing for the next command and i dont know how to do that. Well thanks and any idea is welcome!
Create a new QDialog, insert a Vertical Layout and then put a QPlainTextEdit on top plus a QLineEdit on the bottom. Make the QPlainTextEdit read-only.
Seamus Boyle last edited by
Subclass QPlainTextEdit or QTextEdit and handle key press events yourself; up key for command history, enter for line execute, and so on.
That was my first option but i dont really know how to do that.
[quote author="Seamus Boyle" date="1377418770"]Subclass QPlainTextEdit or QTextEdit and handle key press events yourself; up key for command history, enter for line execute, and so on.[/quote]
Should not be required, I think.
Just connect a signal to QLineEdit::retrunPressed(). This will tell you when the user has typed a new command into the LineEdit. Then just do whatever needs to be done and append the desired output (logging) into the QPlainTextEdit. For details see "Signals and Slots":http://qt-project.org/doc/qt-4.8/signalsandslots.html
Yes i know to do that, actually thats what i did, but i wanted that window to look like it had a console inside of it but it woked fine.
How can i make in the QLineEdit that if i prees up arrow it shows me the last command i wrote there?
Have a look at QLineEdit::setCompleter() and at QCompleter.
wordList << "alpha" << "omega" << "omicron" << "zeta";
QLineEdit *lineEdit = new QLineEdit(this);
QCompleter *completer = new QCompleter(wordList, this);
The "wordList" would simply be the list of recently used commands.
Also check the available QCompleter::CompletionMode values!