Qt 屏蔽Alt + F4 组合键

Qt 屏蔽Alt + F4 组合键

2017年11月16日 10:10:29 linuxwuj 阅读数 2006更多

分类专栏: qt

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/linuxwuj/article/details/78547839

Qt 屏蔽Alt + F4 组合键

有时项目中会有特殊要求,比如屏蔽Alt + F4组合键,防止用户关闭窗口。
查看帮助文档,有如下说明:

[virtual protected] void QWidget::closeEvent(QCloseEvent *event)

This event handler is called with the given event when Qt receives a window close request for a top-level widget from the window system.
By default, the event is accepted and the widget is closed. You can reimplement this function to change the way the widget responds to window close requests. For example, you can prevent the window from closing by calling ignore() on all events.
Main window applications typically use reimplementations of this function to check whether the user's work has been saved and ask for permission before closing. For example, the Application Example uses a helper function to determine whether or not to close the window:
  void MainWindow::closeEvent(QCloseEvent *event)
  {
      if (maybeSave()) {
          writeSettings();
          event->accept();
      } else {
          event->ignore();
      }
  }

如果不需要给出任何提示,可以直接忽略事件即可,如下:

void MainWindow::closeEvent(QCloseEvent *event)
{
    event->ignore();
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值