I wrote my own model sub-classing from QAbstractItemModel, and I am using QTableView class for viewing my model. Since the information which I am viewing is <= 2 symbols, I would like to know how can I resize my item’s rectangle size.
What is the best way to do this?
A few options, in order from easier (but least flexible) to more complicated (but more flexible):
QTableView::resizeColumnsToContentsafter your content is loaded. This may be good enough, and lets the user resize the column if he really wants to.ResizeModeof theQTableView::horizontalHeader(). There are also a bunch ofresize*methods to do this on-the-fly.QStyledItemDelegateand override thesizeHintmethod. This gives you absolute control. See “Subclassing QStyledItemDelegate”.