use QTableWidgetItem::setData() when filling your table. Then all will work out of the box.