jwu
16th January 2018, 15:10
A simple rectangular table.
View inherits from QTreeView.
Model inherits from QAbstractTableModel.
There are checkboxes in column one (Model::data responds to role==Qt::CheckStateRole if col==1).
Model::headerData returns the empty default QVariant for col==1.
View::sizeHintForColumn returns fontMetrics().width('m') for col==1.
Everything works like a charm until I activate View::setHeaderHidden(<someCondition>).
Whenever <someCondition> becomes false and the header reappears, column 1 shrinks by about 50%, and the check boxes are clipped.
Added after 1 11 minutes:
Found the answer: As long as the header is visible, the fontMetrics() reference in View::sizeHintForColumn returns the header font, which is wider than the ordinary font used in the table cells.
View inherits from QTreeView.
Model inherits from QAbstractTableModel.
There are checkboxes in column one (Model::data responds to role==Qt::CheckStateRole if col==1).
Model::headerData returns the empty default QVariant for col==1.
View::sizeHintForColumn returns fontMetrics().width('m') for col==1.
Everything works like a charm until I activate View::setHeaderHidden(<someCondition>).
Whenever <someCondition> becomes false and the header reappears, column 1 shrinks by about 50%, and the check boxes are clipped.
Added after 1 11 minutes:
Found the answer: As long as the header is visible, the fontMetrics() reference in View::sizeHintForColumn returns the header font, which is wider than the ordinary font used in the table cells.