可以单独写一个事件过滤类,然后需要屏蔽Alt+F4键的界面,添加事件过滤到这个类上。
class Handler : public QObject
{
Q_OBJECT
public:
explicit Handler(QObject *parent = 0);
static Handler* GetInstance();
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
private:
bool flag;
};
Handler* Handler::GetInstance()
{
static Handler handler;
return &handler;
}
Handler::Handler(QObject *parent) : QObject(parent)
{
this->installEventFilter(this);
}
bool Handler::eventFilter(QObject *watched, QEvent *event)
{
auto type = event->type();
switch (type) {
case QEvent::KeyPress:
auto key_type = static_cast<QKeyEvent*>(event)->key();
if(key_type == Qt::Key_Alt )
flag = true;
break;
case QEvent::KeyRelease:
auto key_type = static_cast<QKeyEvent*>(event)->key();
if(key_type == Q