PDA

View Full Version : Unable to write in QTextEdit



dikku
29th December 2015, 11:01
I wrote new class inherited from QTextEdit and have keypressevent inside my class called "MyTextEdit.cpp"

Now I want to use this in other class called "MyEditor.cpp", so i created an object of MyTextEdit class and set the setReadOnly() property to false. But it not allow me to write in textedit. I also set it to setEnabled() to true. But still facing same issue.

I think i am missing something or made some silly mistake.

Can anyone let me know what i am doing wrong here.

anda_skoa
29th December 2015, 11:48
In your keyPressEvent() method, do you call the base class implementation?

Cheers,
_

dikku
30th December 2015, 06:17
Yah, but textedit itself not writable, although I can call my kerypressevent, which is not an issue. Issue is i not even get textEdit as writable/editable.

ChrisW67
30th December 2015, 06:51
What you are describing is captured below:


#include <QApplication>
#include <QTextEdit>
#include <QDebug>

class MyTextEdit: public QTextEdit
{
Q_OBJECT
public:
MyTextEdit(QWidget *p = 0): QTextEdit(p) { }
protected:
void keyPressEvent(QKeyEvent *event) {
// do local stuff
qDebug() << "Doing local stuff";
// then do the base stuff
QTextEdit::keyPressEvent(event);
}
};

int main(int argc, char **argv) {
QApplication app(argc, argv);
MyTextEdit edit; // defaults to editable
edit.show();
return app.exec();
}
#include "main.moc"

and this works. So, is this what you are doing?

dikku
30th December 2015, 10:07
yah thanks.

But what you explained, I previously done same thing. And it works if it is as standalone program. But when I do same thing in my application , its not work. and not allows me to edit or write ?? :(

Added after 1 14 minutes:

THANKS TO BOTH OF YOU :) to suggest me some solution.

But I figure out it. I don't know the exact issue, but i tried to re-write my code, it got worked.

Really a Wiered one. In end it got work. lol