PDA

View Full Version : postEvent / selectRow problems with QTableWidget



BH12345
30th October 2012, 18:02
OS: Fedora 14
Qt: 4.7.4

I'm trying to write some code that can remotely operate parts of my Qt GUI. I have a class runs in its own thread listening for incoming connections from python scripts. These connections will simulate certain user interface actions such as clicking a button. I am trying to implement a function that will simulate selecting a row of items in a QTableWidget. I have tried 2 methods and both have been unsuccessful.

Method 1: Use QTableView::selectRow()
The QTableWidget has 4 columns. When selectRow() is called from another thread, only the item in the first column is selected. The itemSelectionChanged() signal does not get emitted as expected.

Method 2: Send a mouseClick Event


QMouseEvent* mouseEvent = new QMouseEvent(QEvent::MouseButtonPress, pos, globalPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QCoreApplication::postEvent(tableWidget, mouseEvent);

The QTableWidget does not apparently receive the QMouseEvent ( I have subclassed QTableWidget and overridden the mousePressEvent() function ).
However, sending a QMouseEvent to the QDialog parent of the QTableWidget works fine. Is there something special about the QTableWidget that doesn't accept posted QMouseEvent's ?

Any help or insight would be much appreciated.

Edit: I figured out the problem with Method 1. The selectRow() does not work properly if it is being called from another thread. I created a custom QEvent and posted it to an eventFilter in the QTableWidget's thread to work.

For Method 2 I discovered that mousePressEvents for QTableWidget are not propagated the same as other widgets. I still do not know how to post a mouse event properly to QTableWidget.