PDA

View Full Version : Qtest QTableWidget



tc
9th November 2009, 15:07
I have used QTest regression tests for QlineEdits QComboBoxes etc. I now wish to use QTest methods on a QTableWidget.

I cannot get the data from, say, the keyClicks method to appear in the "selected" cell of the QTableWidget.
Can I "select" a cell by using QTest::mouseClick?
QTableWidget items are not QWidgets - is that a fundamental problem?
As QTableWidgetItem is not derived from QWidget, can I even use keyClicks?
Any advice on testing QTableWidgets using QTest?

Regards

TC

jillian
2nd March 2010, 22:47
This is how I interact with a QTableWidget when using the QTest namespace:

//Find the item in the table that you want to interact with
QList<QTableWidgetItem *> item_list = table_widget->findItems("My Special Item", Qt::MatchExactly);

//Identify the visual rectangle that contains this table item
QRect item_rect = table_widget->visualItemRect(item_list[0]);

//Move the mouse to the rectangle's center point, in the table's viewport
QTest::mouseMove(table_widget->viewport(), item_rect.center());

//Click on that table widget item
QTest::mouseClick(table_widget->viewport(), Qt::LeftButton, Qt::NoModifier, item_rect.center());

Hope this helps you!