我目前正在实现一个在后台使用openGL渲染的触摸设备的QML应用程序。我用这个谈话https://www.youtube.com/watch?v=GYa5DLV6ADQ作为我工作的基础。在QQuickView上没有触发的触摸事件
总之,我正在使用自定义QQuickView并将选项“clearbeforerendering”设置为false以便能够绘制我的openGL内容。除此之外,我想在我的自定义QQuickView中接收touchEvents以实时修改我的OpenGL渲染。
Unfornately,touchEvent从不触发,而我正确接收不同的mouseEvents。我在QOPenGLWindow上试过这段代码并正确接收了touchEvents,所以问题不是来自我的设备。
这里是我的代码中的一些部分可能会有所帮助:
的main.cpp
#include "tableclothwindow.h"
#include "target.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDesktopWidget dw;
TableclothWindow *mainWindow = new TableclothWindow();
mainWindow->setMinimumSize(QSize(dw.width(),dw.height()));
mainWindow->setSource(QUrl(QStringLiteral("qrc:/main.qml")));
mainWindow->show();
mainWindow->initializeQMLInteraction();
return app.exec();
}
main.qml
Item
{
id: container
Text {
objectName: "text"
id: helloText
text: "Hello world!"
x: 100
y: 80
color: "#00FF00"
opacity: 0.8
font.pointSize: 24; font.bold: true
MouseArea{
onClicked: helloText.color = "FF0000"
}
}
}
tablecloth.cpp(定制QQuickView)
#include "tableclothwindow.h"
#include "tableclothscene.h"
TableclothWindow::TableclothWindow(QWindow *parent)
:QQuickView(parent),
m_mousePressed(false),
m_firstTime(true),
m_targetCentroid(QPointF(0,0)),
m_scene(new TableclothScene)
{
// disable auto-clear for manual openGL rendering
setClearBeforeRendering(false);
QObject::connect(this, SIGNAL(beforeRendering()), SLOT(renderOpenGLScene()), Qt::DirectConnection);
// update visuals
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(update()));
m_timer->start(30);
}
TableclothWindow::~TableclothWindow()
{
}
// openGL rendering functions
void TableclothWindow::renderOpenGLScene()
{
if(m_firstTime){
m_scene->initialize();
m_scene->resize(width(),height());
assignLinkedPointMass();
m_firstTime = false;
}
m_scene->render();
}
void TableclothWindow::update()
{
if(!m_firstTime){
updateTargetPosition();
m_scene->update();
QQuickView::update();
}
}
// event handling
// working
void TableclothWindow::mousePressEvent(QMouseEvent *event)
{
event->accept();
qDebug() << "mouse pressed"
}
// Doesn't work
void TableclothWindow::touchEvent(QTouchEvent *event)
{
event->accept();
qDebug() << " touch detected";
}
做一个nyone知道为什么touchEvents不会在自定义QQuickView中被触发?