Results 1 to 1 of 1

Thread: postEvent / selectRow problems with QTableWidget

  1. #1
    Join Date
    Oct 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default postEvent / selectRow problems with QTableWidget

    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

    Qt Code:
    1. QMouseEvent* mouseEvent = new QMouseEvent(QEvent::MouseButtonPress, pos, globalPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    2. QCoreApplication::postEvent(tableWidget, mouseEvent);
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by BH12345; 30th October 2012 at 23:26.

Similar Threads

  1. Replies: 3
    Last Post: 22nd March 2010, 13:50
  2. QTableWidget problems
    By eleanor in forum Qt Programming
    Replies: 6
    Last Post: 22nd May 2009, 13:18
  3. qtableview selectrow(s)
    By JeanC in forum Qt Programming
    Replies: 1
    Last Post: 9th May 2008, 10:01
  4. postEvent & Thread problems
    By gianpatt in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2008, 14:19
  5. selectRow()
    By gyre in forum Newbie
    Replies: 9
    Last Post: 11th December 2007, 20:49

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.