【发布时间】:2016-09-14 10:36:43
【问题描述】:
我在 QT 应用程序中将 MouseArea 用于按钮,并且需要知道用户何时在触摸按钮时移动手指。在 W7 上使用鼠标,我从 MouseArea 使用 onEntered 获取此信息。
问题:在带有触摸屏的目标平台上,只有当我按下 MouseArea(首先触摸 MouseArea 内),然后将手指移出(exited-signal),然后再将手指移回时,才会触发输入信号(输入信号)。但是当第一次触摸在该区域之外并且我进入它时,不会触发输入信号。 我还尝试了使用 onTouchUpdated 和 onUpdated 的 MultiPointTouchArea,同样的行为。
我在嵌入式 linux 上使用 Qt 5.5.1。
我可以做些什么来让 MouseArea 总是触发输入的信号吗?还是应该使用 MouseArea 或 MultiPointTouchArea 以外的东西?
作为一种解决方法,我可以在整个窗口上考虑一个 MouseArea,其中包含所有按钮所在的信息,并检查每个 positionChanged(如果输入了按钮),但我确信一定有更好的解决方案。
编辑:在目标平台上使用鼠标时,将鼠标移入该区域时会触发输入信号。
这是我的(简化的)代码:
main.cpp
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QtQml>
#include "uart_terminal.h"
int main(int argc, char *argv[])
{
system("mount /dev/mmcblk0p1 /mnt/sdcard/");
setenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", "376", 1);
setenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", "301", 1);
QApplication app(argc, argv);
qmlRegisterType<UART_terminal>("com.uart", 1, 0, "UARTTerminal");
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("applicationDirPath", QGuiApplication::applicationDirPath());
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
main.qml:
Window
{
id: rootWindow
visible: true
width: 1280
height: 1024
Rectangle
{
id: test
color: "red"
width: 300
height: 300
MouseArea
{
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.AllButtons
onEntered:
{
console.log("entered")
test.color = "blue"
}
onExited: test.color = "red"
onCanceled: console.log("canceled")
onPositionChanged:
{
console.log("pos changed, containsMouse", containsMouse)
}
}
/*MultiPointTouchArea
{
anchors.fill: parent
onTouchUpdated: console.log("touch updated")
onUpdated: console.log("touchlist updated")
}*/
}
}
【问题讨论】: