How to put the scrollbar at the bottom when I try to achieve a terminal-like dialog using QTextedit and QScrollbar?
-
Here is the situation:
I'm using QProcess to communicate with an external process. This process originally outputs its data into the terminal and now I want to redirect its output to my QT dialog. I'm using this method:
@connect(mac_phy_Process, SIGNAL(readyReadStandardOutput()), this, SLOT(updateOutPutEdit()));@
As you can see, the external process is 'mac_phy_Process' and I'm using readyReadStandardOutput() signal to communicate with it, when I catch this signal, I will update my QTextedit, here is my updateOutPutEdit slot:
@void Configure::updateOutPutEdit(){
QByteArray newData = mac_phy_Process->readAllStandardOutput();
QString text = QString::fromLocal8Bit(newData);
outPut->outPutWindow->insertPlainText(text);
(outPut->scrollBar)->setValue(outPut->scrollBar->maximum());
}@The 'output' is my dialog. 'outPutWindow' is a QTextEdit.
I don't think my method is good, it isn't good for sure. Because the data comes quickly and everytime the data comes, I will put the scrollbar to the bottom location, this will prevent the user to drag it up, the user cannot see the output previously written.I'm figuring out a better way which I don't know, is there anyone who can help me with this ? thanks.
Another problem: is there a size limit of QTextEdit? It turns out that everytime the QTextEdit cannot get the same output as terminal does, the QTextEdit loses data! -
Hi HYSuperman
i think that if you set -1 for QTextEdit max-length it's change to unlimited, test it for yout own project and post your experience as reply. -
I cannot find this function? What's its name ?
[quote author="a.jafarabadi" date="1410588476"]Hi HYSuperman
i think that if you set -1 for QTextEdit max-length it's change to unlimited, test it for yout own project and post your experience as reply.
[/quote] -
check this thread it's useful:
http://qt-project.org/faq/answer/how_can_i_get_set_the_max_length_of_a_qtextedit
try it and come back to solve first problem
;)