Is it possible to sort the headers of a QTableView?

I'd like to sort the horizontal and vertical headers. QTableView only offers functionality to sort a column's contents. Is there a way to sort the view or do I have to sort the underlying datastructures?