現在、バックグラウンドでOpenGLレンダリングを使用するタッチデバイス用のQMLアプリケーションを実装しています。私はこの話を私の仕事の基礎としてhttps://www.youtube.com/watch?v=GYa5DLV6ADQとしました。タッチイベントがQQuickViewでトリガされていません
要するに、私はカスタムQQuickViewを使用していて、 "clearbeforerendering"をfalseに設定してOpenGLコンテンツを描画しています。それに加えて、カスタムQQuickViewでtouchEventsを受け取って、リアルタイムでOpenGLレンダリングを変更したいと考えています。
まったく別のmouseEventを受け取っている間、私はうっとりしてtouchEventを引き起こすことはありません。私はこのコードを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";
}
aカスタムQQuickViewでtouchEventがトリガーされない理由を知っていますか?