Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the slot that gets called when the signal is emitted you can get the text with <code>QString str = textEdit-&gt;toplainText();</code>. Also you can store the previous version of the string and compare to get the character that was added and its position.</p> <p>Regarding the cursor position you can us QTextCurosr class as in this example:</p> <p>widget.h file:</p> <pre><code>#ifndef WIDGET_H #define WIDGET_H #include &lt;QWidget&gt; #include &lt;QTextEdit&gt; #include &lt;QTextCursor&gt; #include &lt;QVBoxLayout&gt; #include &lt;QLabel&gt; class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = 0); ~Widget(); private slots: void onTextChanged(); void onCursorPositionChanged(); private: QTextCursor m_cursor; QVBoxLayout m_layout; QTextEdit m_textEdit; QLabel m_label; }; #endif // WIDGET_H </code></pre> <p>widget.cpp file:</p> <pre><code>#include "widget.h" #include &lt;QString&gt; Widget::Widget(QWidget *parent) : QWidget(parent) { connect(&amp;m_textEdit, SIGNAL(textChanged()), this, SLOT(onTextChanged())); connect(&amp;m_textEdit, SIGNAL(cursorPositionChanged()), this, SLOT(onCursorPositionChanged())); m_layout.addWidget(&amp;m_textEdit); m_layout.addWidget(&amp;m_label); setLayout(&amp;m_layout); } Widget::~Widget() { } void Widget::onTextChanged() { // Code that executes on text change here } void Widget::onCursorPositionChanged() { // Code that executes on cursor change here m_cursor = m_textEdit.textCursor(); m_label.setText(QString("Position: %1").arg(m_cursor.positionInBlock())); } </code></pre> <p>main.cpp file:</p> <pre><code>#include &lt;QtGui/QApplication&gt; #include "widget.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.show(); return a.exec(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload