QTest click a Widget



  • Hi,

    why is it possible to click a non-nested widget and impossible to click a nested widget directly? It's was no good workflow for automated gui-testing when I first musst get the child to click them..

    Example:
    click works directly:
    @
    QPushButton *button= new QPushButton( "push" );
    button->show();

    while ( !button->isVisible() ) {
    }
    QTest::qWait( 200 );

    const int positionXButton = 50;
    const int positionYButton = 15;
    QTest::mouseMove ( button, QPoint( positionXButton , positionYButton ), -1 );
    QTest::mouseClick( button, Qt::LeftButton, Qt::NoModifier, QPoint( positionXButton , positionYButton ), 100
    @

    works only with childAt() and then click:
    @
    QPushButton *button2 = new QPushButton();
    QVBoxLayout *vLayout = new QVBoxLayout();
    QWidget *myWidget = new QWidget();
    vLayout->addWidget( button2 );
    myWidget->setLayout( vLayout );
    myWidget->show();

    while ( !myWidget->isVisible() ) {
    }
    QTest::qWait( 200 );
    QTest::mouseMove ( myWidget, QPoint( positionXButton , ( positionYButton + 30 ) ), -1 );
    QTest::mouseClick( myWidget, Qt::LeftButton, Qt::NoModifier, QPoint( positionXButton , ( positionYButton + 30 ) ), 100 );
    std::cout << "-------------- Button clicked! nothing happens ------------------" << std::endl;
    QTest::qWait( 2000 );
    QWidget *myButton = myWidget->childAt( positionXButton , ( positionYButton + 30 ) );
    if ( QPushButton reallyMyButton= qobject_cast<QPushButton>(myButton ) ) {
    QTest::mouseClick( reallyMyButton, Qt::LeftButton, Qt::NoModifier, QPoint(), 100 );
    std::cout << "-------------- Button clicked! it works...------------------" << std::endl;
    }
    @
    In normal widegts it is impossible to get access to the member of these widgets because they private, so use the button widget and not the "outer" widget is no solution.
    Is childAt() the only way to get access or can i use something like this
    @
    QPushButton *currentButton = findWidget("myWidget.button2");
    @

    to get access to the widget
    Thanks for help


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.