I have a QTextEdit box that displays text that is clickable. After clicking the text I want the cursor to move to the line after the last line of text so that new text can be displayed without interfering with what already exists. My problem is that new text is displayed from the position I clicked the text from instead of moving to the next empty line. Here are the relevant classes.
void Dialog::handleButton()
{
QString input= lineEdit->text();
lineEdit->clear();
//statValue->setText("0");
smallEditor->append("\n");
smallEditor->insertPlainText(input);
bigEditor->append("\n");
bigEditor->insertPlainText(input);
std::string inp = input.toStdString();
//std::cout<<inp<<std::endl;
}
void Dialog::createFormGroupBox()
{
formGroupBox = new QGroupBox(tr("History"));
QFormLayout *layout = new QFormLayout;
bigEditor = new QTextEdit();
bigEditor->setReadOnly(true);
connect(bigEditor, SIGNAL(cursorPositionChanged()), this, SLOT(on_textEdit_clicked()));
layout->addWidget(bigEditor);
formGroupBox->setLayout(layout);
}
void Dialog::on_textEdit_clicked()
{
QTextCursor cursor;
QString text;
cursor = bigEditor->textCursor();
cursor.movePosition(QTextCursor::StartOfBlock);
cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
text = cursor.selectedText();
std::string txt = text.toStdString();
std::cout<<txt<<std::endl;
}
I tried using both KeepAnchor and MoveAnchor but neither made a difference.