简体   繁体   English

qt-同时按下多个QPushButton

[英]qt - Pushing multiple QPushButtons at the same time

I couldn't find an answer to this so here goes nothing: I'm developing a GUI for an embedded Linux and it needs to be able to push 2 buttons and do different functions when one of the 2 is already pushed (like a shiftbutton on your keyboard). 我找不到答案,所以什么也没做:我正在为嵌入式Linux开发GUI,它必须能够按2个按钮并在已经按2个按钮之一的情况下执行不同的功能(例如shiftbutton)在键盘上)。 I tried using button->setAutoRepeat(true); 我尝试使用button->setAutoRepeat(true); It does what it says but it doesn't allow other buttons to be pressed at the same time. 它按其说的进行操作,但不允许同时按下其他按钮。 The embedded Linux system has a 10-finger touchscreen so it should allow multiple buttons at the same time. 嵌入式Linux系统具有10指触摸屏,因此它应同时允许多个按钮。

TL;DR: I can't find a way to press another button while a button is already pressed. TL; DR:在已按下某个按钮的情况下,我无法找到一种方法来按下另一个按钮。

Solution 1: Use QAbstractButton::isDown() to check if the shift like button is down when processing event in the action button. 解决方案1:使用QAbstractButton :: isDown()检查在处理动作按钮中的事件时,类似移位按钮是否处于按下状态。

Solution 2: QAbstractButton hsd setChecked/isChecked functions which can be useful. 解决方案2:QAbstractButton hsd setChecked / isChecked函数可能很有用。

Solution 3: Subclass the QPushButton and reimplement keyPressEvent or you can install event filter for your button and process QMouseEvent. 解决方案3:子类化QPushButton和重新实现keyPressEvent,或者您可以为按钮安装事件过滤器并处理QMouseEvent。 This solution will give you more flexibility in your code. 该解决方案将为您提供更大的代码灵活性。

Choose one of it depending on usage and requirement. 根据用途和要求选择其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM