OK, here is the answer I came up with by myself:

Qt Code:
  1. self.tableView.setItem(i, 2, QTableWidgetItem(str(create_dataframe(res)[2][i])))
  2. it3.setData(Qt.EditRole, QVariant(create_dataframe(res)[3][i]))
  3. self.tableView.setItem(i, 3, it3)
To copy to clipboard, switch view to plain text mode 

I.e. there is no need to transform datetime value: it can be properly sorted in string form. As for integer values, I have to create an instance of QTableWidgetItem(), then use .setData with QVariant on it. After this I can setItem to the table.