5

In QLineEdit, there is a textEdit() signal, which only emits if the user changes the text, but not when you call setText(),

So what's the equivalent in QTextEdit? I only see a textChanged() signal, and the documentation states it is emitted whenever the text document changes.

EDIT

I want to implement an auto-save feature, with a QTimer of course,

So when you start editing the document, the timer starts, and when timed out, I save the text inside the widget.

Daniel Hedberg
  • 5,677
  • 4
  • 36
  • 61
daisy
  • 22,498
  • 29
  • 129
  • 265

2 Answers2

12

You can block signals of the QTextEdit widget whenever you insert/modify the contents yourself, and then release the block when you're done. By doing that the signal will only be emitted when the user makes changes to the contents.

bool QObject::blockSignals(bool block)
Daniel Hedberg
  • 5,677
  • 4
  • 36
  • 61
0

I looked for my mentor's code and he solved the problem this way:

  1. Install event filter for QTextEdit object (this is pointer to mEdit holder, which is QWidget)
mEdit->installEventFilter(this);
  1. Override QObject::eventFilter method in class, which contains QTextEdit object (remember, it's QWidget inheritor)
//override
bool CustomEditWidget::eventFilter(QObject *watched, QEvent *event)
{
    if(watched == mEdit && event->type() == QEvent::FocusOut){
        changeValue(mEdit->toPlainText());
    }
    return false;
}

The rest you can see in the documentation, there are examples: https://doc.qt.io/qt-6/qobject.html#eventFilter

sedub01
  • 71
  • 6