我想在用戶發佈時撥打一些自定義複製代碼Ctrl + C。當C在Ctrl之前發佈時,Qt發送與QKeySequence::Copy
匹配的關鍵事件。當Ctrl在C之前發佈時,發佈事件不匹配。如何在Ctrl'C'之前釋放Ctrl時用Qt捕捉Ctrl + C鍵事件?
當按鍵釋放事件開始與按Ctrl,有沒有辦法,看看是否仍然被按住Ç?
當我不處理Ctrl首先被釋放,事件被傳遞,它做一個正常的副本,這正是我不想發生的事情。
bool
MyWidget::eventFilter(QObject* object, QEvent* event)
{
// the text edit box filters its events through here
if (object == m_text_edit_box)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *key_event = static_cast<QKeyEvent*>(event);
if (key_event->matches(QKeySequence::Copy))
{
// don't do anything and don't pass along event
return true;
}
}
else if (event->type() == QEvent::KeyRelease)
{
QKeyEvent *key_event = static_cast<QKeyEvent*>(event);
if (key_event->matches(QKeySequence::Copy))
{
// we only get in here if 'c' is released before ctrl
callCustomCopy();
return true;
}
}
}
// pass along event
return false;
}