Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTest click a Widget
Forum Updated to NodeBB v4.3 + New Features

QTest click a Widget

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LongJohn
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved