Best event for QtableWidget to add subrecords in pyqt
<p>I have a relational database with 2 related tables.
Also <code>psycopg2</code> adapter were used to retrieve data.There are two <code>QtableWidget</code> to display data from two related tables in ui.
What is the appropriate event (from <code>QtableWidget</code> events) to detect new record is selected or filled into main <code>QtableWidget</code> to proceed second query and filling sub records into other <code>QtableWidget</code>?</p>

<pre><code>self.tableWidget.itemSelectionChanged.connect(self.main_table_current_row_changed)
</code></pre>

<p>the above event were used but just user click is necessary.
Any idea is apreciated.
thank you</p>

<p>You probably want to connect to the <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qtablewidget.html#itemSelectionChanged" rel="nofollow">itemSelectionChanged</a> signal.</p>

<pre><code>def __init__(...)
    ...
    self.table1.itemSelectionChanged.connect(self.update_table2)

def update_table2(self):
    items = self.table1.selectedItems()
    # Update table2 based on table1 selection
</code></pre>

python pyqt relational-database psycopg2 qtablewidget