1

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.

FXQuantTrader
  • 6,821
  • 3
  • 36
  • 67
Andreas
  • 636
  • 1
  • 12
  • 29
  • I think you need to send mouse click event to the combo box and not to the widget: `QTest::mouseClick(type...`. Use coordinates that correspond to the combo box coordinates system. – vahancho Dec 09 '13 at 11:05
  • In this case it's possible but what is the solution when the combobox is a private member of the widget? – Andreas Dec 09 '13 at 11:18
  • 1
    Please look at my answer: http://stackoverflow.com/questions/20394236/qtest-mouseclick-on-a-qpushbutton/20396911#20396911 – vahancho Dec 09 '13 at 11:34
  • I know this answer of you but is this the only way to get access to the button? I search for a solution without the childAt() function only move the mouse over the widget an click it... – Andreas Dec 09 '13 at 11:58
  • I see, but you want to click on one widget, but get effect on to another? I admit I do not know such a way. – vahancho Dec 09 '13 at 12:17
  • I want to test the gui fast and esay. I'am not happy about the step childAt(), when I test the gui I want to click a Button and not to find it first on a position and then click it.. – Andreas Dec 09 '13 at 12:28

0 Answers0