I have a solution, I can work with.
First I implement mousePressEvent
from QQuickView
in a derived class.
Then with findChildren<QObject*>
on the QQuickView
object, I can find and debug the QML objects. Strangely, childAt
and children
do not list the QML child objects.
void ClickView::mousePressEvent( QMouseEvent* ev ) {
QObjectList children = this->findChildren<QObject*>( QRegularExpression( ".+" ) );
for( QObject* child : children ) {
// only search for QML types
if( !strstr( child->metaObject()->className(), "_QMLTYPE_" ) ) { continue; }
QVariant vX = child->property( "x" );
QVariant vY = child->property( "y" );
QVariant vW = child->property( "width" );
QVariant vH = child->property( "height" );
if( vX.isValid() && vY.isValid() && vW.isValid() && vH.isValid() ) {
QRect rect( vX.toInt(), vY.toInt(), vW.toInt(), vH.toInt() );
if( rect.contains( ev->pos() ) ) {
qDebug() << child;
}
}
}
QQuickView::mousePressEvent( ev );
}
The complete project is here:
https://github.com/elsamuko/qml_demo
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…