
Originally Posted by
Sarma
I could see the message on the console. But the thing is that I could catch the event only when I double click along the borders of TextEdit.
Seems so. So the double click event goes to some child of the text edit.

Originally Posted by
Sarma
What is the procedure of making it onto the whole TextEdit area. Please help me out.
I did a little test.
I installed the same event filter also to all child objects of the text edit:
te->installEventFilter(this);
QObjectList children = te->children();
foreach (child, children)
{
child->installEventFilter(this);
}
te->installEventFilter(this);
QObject* child = 0;
QObjectList children = te->children();
foreach (child, children)
{
child->installEventFilter(this);
}
To copy to clipboard, switch view to plain text mode
Then in the event filter I printed the name of the object like this:
if (e
->type
() == QEvent::MouseButtonDblClick) {
qDebug() << o->objectName();
return true;
}
if (e->type() == QEvent::MouseButtonDblClick)
{
qDebug() << o->objectName();
return true;
}
To copy to clipboard, switch view to plain text mode
The output was: "qt_scrollarea_viewport"
So, the conclusion:
QTextEdit inherits QScrollView (or QScrollArea in Qt 4, which I'm using), and it's the viewport child which seems to receive the double click event.
The solution:
{
//various child widgets are added
te->installEventFilter(this);
te->viewport()->installEventFilter(this);
//some other widgets
}
CPT::CPT(QWidget *parent):QWidget(parent)
{
//various child widgets are added
QTextEdit *te=new QTextEdit(this);
te->installEventFilter(this);
te->viewport()->installEventFilter(this);
//some other widgets
}
To copy to clipboard, switch view to plain text mode
Bookmarks