PDA

View Full Version : QPlainTextEdit reimplementation



qt_developer
14th November 2012, 11:43
Hi all,

I have reimplemented a QPlainTextEdit class to get the text inserted by the user, my code:



#ifndef PLAINTEXTEDIT_H
#define PLAINTEXTEDIT_H

#include <QPlainTextEdit>

namespace Ui {
class GPlainTextEdit;
}

class GPlainTextEdit : public QPlainTextEdit
{
Q_OBJECT

public:
explicit GPlainTextEdit(QWidget *parent = 0);
~GPlainTextEdit();

protected:
void keyPressEvent(QKeyEvent *e);

private:
Ui::GPlainTextEdit *ui;
};

#endif // PLAINTEXTEDIT_H




#include "gplaintextedit.h"
#include "ui_gplaintextedit.h"

#include <QDebug>

GPlainTextEdit::GPlainTextEdit(QWidget *parent) :
QPlainTextEdit(parent),
ui(new Ui::GPlainTextEdit)
{
ui->setupUi(this);

connect(this, SIGNAL(textChanged()), this, SLOT(onCustomContextMenuRequested()));
qDebug() << "GPlainTextEdit::GPlainTextEdit()";
}

GPlainTextEdit::~GPlainTextEdit()
{
delete ui;
}

void GPlainTextEdit::keyPressEvent(QKeyEvent *e)
{
qDebug() << "GPlainTextEdit::keyPressEvent(QKeyEvent *e)";
}




<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GPlainTextEdit</class>
<widget class="QPlainTextEdit" name="GPlainTextEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>104</width>
<height>64</height>
</rect>
</property>
</widget>
<resources/>
<connections/>
</ui>


Then, in another widget, I have created a promoted widget using the reimplemented class, but the method 'keyPressEvent(QKeyEvent *e)' is not called.

I have put a log in the GPlainTextEdit constructor, but it isn't shown.

I have used the debugger in the QPlainTextEdit constructor call, but I can't step into.

Any help is appreciated.

Best regards.

amleto
14th November 2012, 13:21
all of that probably means your widget is never created. show more code (read my sig)!

qt_developer
14th November 2012, 15:22
I have made clean + run qmake and now works properly.