Gtk3 rich text widget machine (based on GtkTextBuffer and GtkTextView ) has "begin-user-action" and "end-user-actions" , which allows you to quickly process user input (and distinguish it) from the generated application changes to the buffer or view).
But it seems like there are no similar things in Qt5. For example, my incomplete understanding is that QTextEdit :: insertHtml or QTextDocument :: contentChanged or QTextDocument :: contentsChanged does not separate the changes associated with user input (keyboard or insert, etc.) ..) from those that are executed application.
I mean some syntax oriented editor.
Perhaps I misunderstand support for Qt5 text editor support.
(For curious people: I will redesign and reorient my MELT monitor from C and GTK to something with C ++ 11 and Qt5, conditionally called Basixmo ; all this is free GPL software, but I haven't encoded the Qt5 thing yet)
Example
I have a window with a button sayand QTextEditas its central widget. When I click the button, a line is inserted in the document "hello", and I call that the application changes (you can imagine that the button is replaced by something not related to the user, for example, some network input). When I enter some keystrokes in a text editor, some lines are also inserted from this custom action change. I want to distinguish between one and the other.
#include <QApplication>
#include <QMainWindow>
#include <QTextEdit>
#include <QToolBar>
#include <fstream>
#include <iostream>
int main(int argc, char**argv)
{
QApplication app(argc, argv);
auto win = new QMainWindow;
auto tb = win->addToolBar("Basile example");
auto ted = new QTextEdit;
win->setCentralWidget(ted);
tb->addAction("say",[=]{ted->insertPlainText("hello");});
auto doc = ted->document();
QObject::connect(doc,&QTextDocument::contentsChange,
[=](int pos, int removedchars, int addedchars)
{ std::clog << "contentChange: pos=" << pos
<< " removedchars=" << removedchars
<< " addedchars=" << addedchars
<< std::endl; });
win->show();
app.exec();
delete win;
}
But when I run the above code, the signal contentsChange(connected to my lambda function outputting to std::clog) is triggered both for user action changes and for application changes.
QTextEdit QTextDocument QTextCursor, ( QTextEdit , ..) . (, QWidget::keyPressEvent ..), , , , QTextEdit.
, : , emacs Qt5 ++ 11 (, à la Guile).
PS. , Debian/testing/x86-64. Qt - 5.6.1, GCC 6.2; .