Hello friends,
I have a subclassed qtextedit in a QMAinwindow. So my target is to achieve that the key events from textedit
are handled in Mainwindow event system. so when I make this:
//**************************************************************************
class keyPressCatcher
:public QObject//**************************************************************************
{
public:
{};
~keyPressCatcher()
{};
{
if (event
->type
() == QEvent::KeyPress) {
QKeyEvent *keyEvent
= dynamic_cast<QKeyEvent
*>
(event
);
std::cout << "You Pressed " << keyEvent->text().toStdString() << "\n";
return true;
}
else
{
// standard event processing
return QObject::eventFilter(object, event
);
}
};
};
//**************************************************************************
class keyPressCatcher:public QObject
//**************************************************************************
{
public:
keyPressCatcher():QObject()
{};
~keyPressCatcher()
{};
bool eventFilter(QObject* object,QEvent* event)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = dynamic_cast<QKeyEvent *>(event);
std::cout << "You Pressed " << keyEvent->text().toStdString() << "\n";
return true;
}
else
{
// standard event processing
return QObject::eventFilter(object, event);
}
};
};
To copy to clipboard, switch view to plain text mode
and install the eventfilter
this->installEventFilter(new keyPressCatcher());
and textedit->installEventFilter(this);
this->installEventFilter(new keyPressCatcher());
and textedit->installEventFilter(this);
To copy to clipboard, switch view to plain text mode
nothing appears.
So my question is what the the basic step to achieve this functionality?
Thanx in advance
Bookmarks