2016-05-31 13 views
0

現在、バックグラウンドで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がトリガーされない理由を知っていますか?

答えて

1

調査の結果、Qtドキュメントで言われていることにもかかわらず、touchEventsがQQuickViewにディスパッチされなかったことがわかりました。

問題を解決するには、QWindowのQtイベントディスパッチャー(QQuickViewが継承する)のQ​​Event:イベント(Event *)でtouchEventsを処理する必要がありました。私はあなた自身がイベントを伝播したり、イベント機能のように使用することができますが、バグか見落としかどうか疑問に思います。ここで

は私がそれを終わったコードですが、それがクリーンであるかどうかはわかりませんが、それは動作します。..

bool TableclothWindow::event(QEvent *event) 
    { 
     event->accept(); 
     if(event->type() == QEvent::TouchEvent){ 
      QTouchEvent *touchEvent = static_cast<QTouchEvent*>(event); 
      //handling the touchEvent 
     } 
     return QQuickView::event(event); 
    } 

はそれが質問がダウンなしで投票されていても、誰かを助けるかもしれないホープ理由が与えられた。

関連する問題