PDA

View Full Version : QTextEdit and EditEvent



Pablik
19th June 2012, 15:28
Hi i need help with QTextEdit, i want make smart QTextEdit who know if it was edited (insert, delete some chars), so i want reimplement class QTextEdit and add :
- bool verbal "isEdited" - its done
- event who will by know if somting was edit in my QTextEdit

MyTextEdit


#ifndef MYTEXTEDIT_H
#define MYTEXTEDIT_H

#include <QtGui>
#include <QtCore>

class MyTextEdit : public QTextEdit
{
Q_OBJECT
public:
explicit MyTextEdit(QWidget *parent);

private:
bool isEdited;
signals:

public slots:

protected:

};

#endif // MYTEXTEDIT_H



#include "mytextedit.h"

MyTextEdit::MyTextEdit(QWidget *parent)
{
setParent( parent );
isEdited = false;

}


I try write somting with use KeyEvent but if sombody select and delete or past with the help of mouse then my QTextEdit will by dont konow about this edit.
Coud you help me with that ??

Pablik
19th June 2012, 22:24
Srry but i didnt see signal "textChanged()"

d_stranz
20th June 2012, 15:21
This code probably won't work correctly in any case, since you aren't allowing the QTextEdit base class to be properly constructed. Your code should look like this:


#include "mytextedit.h"

MyTextEdit::MyTextEdit(QWidget *parent)
: QTextEdit( parent )
, isEdited( false )
{
}

The base class constructor must be called in order to properly construct the entire inheritance hierarchy. There is no need to call setParent() (which you probably did because things weren't working right, I'll bet), because invoking the base class constructor does that already.

wysota
21st June 2012, 15:13
Why not just use QTextDocument::modified?