Simplest way to click a button with QTest

2.1k views Asked by At

Can somebody explain me the simplest way to click a button or something else like a QComboBox in a QTest?

I tried this:

QComboBox *type = new QComboBox();
type->addItem( "1" );
type->addItem( "2" );
type->addItem( "3" );
type->addItem( "4" );

QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->addWidget( type);

QWidget *myWidget = new QWidget();
myWidget->setLayout( vLayout );

myWidget->show();

while ( !myWidget->isVisible() ) {
 QTest::qWait(400);
}

const int positionXTypeBox = 70;
const int positionYTypeBox = 25;

QTest::mouseMove ( myWidget, QPoint( positionXTypeBox, positionYTypeBox ), -1 );
QTest::qWait( 1500 );
QTest::mouseClick( myWidget, Qt::LeftButton, Qt::NoModifier, QPoint( positionXTypeBox, positionYTypeBox ), 100 );

The mouse was exactly over the QComboBox-Widget but nothing happens when the mouse is clicked.

Thanks.

0

There are 0 answers