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::resizeColumnsToContents
after your content is loaded. This may be good enough, and lets the user resize the column if he really wants to.ResizeMode
of the QTableView::horizontalHeader()
. There are also a bunch of resize*
methods to do this on-the-fly.QStyledItemDelegate
and override the sizeHint
method. This gives you absolute control. See "Subclassing QStyledItemDelegate".