View Full Version : Simulating item selection in QTreeView.

28th September 2010, 12:48
How could I simulate a mouse click on a row of a QTreeView. For QPushButton we have click() function to simulate a mouse click, but I couldn't find anything which can help me to generate a mouse click on a QTreeView item.
Any help will be appreciated.

28th September 2010, 14:17
Why do you want to do that? I mean what is your ultimate goal for doing that.

28th September 2010, 15:56
I want to test my QTreeView items. At the moment when I click on the items my UI is transitioning from one state to another. I want to do the same thing by simulating the mouse click.

28th September 2010, 16:22
You can post a mouse press/mouse release event pair to the widget using QCoreApplication::postEvent()

5th October 2010, 12:56
I got the solution. If someone wants to simulate a mouse click on QTreeView items, you can use QTest::mouseClick( QWidget * widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay = -1 ) function.For me it works like a charm.