gpt4 book ai didi

Qt:检测特定 QWidget 之外的 mousePressEvent

转载 作者:行者123 更新时间:2023-12-01 13:32:11 43 4
gpt4 key购买 nike

我有一个包含多个子对象的小部件,用户可以通过单击它们来选择它们。

我想在用户点击小部件外部时清除当前选择,我想知道如何最好地检测这些点击。

一些约束:

  • 通过eventFilter吃掉周围对象的mousePressEvents是不太可行的。
  • 如果我可以避免使用 grabMouse(),我愿意,因为来自 the docs 的警告:

    Warning: Bugs in mouse-grabbing applications very often lock the terminal. Use this function with extreme caution, and consider using the -nograb command line option while debugging.

我还有其他选择吗?

注意:此应用将跨平台部署(至少是 Windows 和 Ubuntu)

最佳答案

我倾向于使用 QWidget 的 focusOutEvent

简单地检查您的小部件是否失去焦点

关于Qt:检测特定 QWidget 之外的 mousePressEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8186015/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com