Unsolved QHeaderView::sectionResizeMode not applied changing font size, family, etc.
-
Hello, all.
If the font size of
QHeaderView
's sections is increased either through QSS:QHeaderView::section:horizontal { font-size: 14pt; }
or by means of C++:
QWidget::setFont
setting the
QHeaderView::sectionResizeMode
toQHeaderView::ResizeToContents
doesn't fit the contents of the whole column correctly - the header's title is cut either from one or from both sides. The contents are fit correctly only when the font size matches some standard one - presumably, the application one. If the font size - be it the pixel or point one, is greater than this reference value, cutting takes place. Made aQStyledItemDelegate
subclass and overrode theQStyledItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index)
, so that to dump the available fonts. Neither the cell's fontoption.font
nor that of the whole headeroption.widget->font()
had the requested font size and, presumably, this is the reason for the incorrect size hint calculation. Looked at the sources ofQStyledItemDelegate
,QCommonStyle
,QWindowsStyle
, etc. for the way the size hint is calculated but to figure out the exact place and reason why the correct font is not taken into consideration would take time.Any suggestions are welcome how to make
QTableView
orQTreeView
correctly take into consideration the font when calculating the size hint.Another similar issue is the positioning of the sort indicator relatively to the rest of the cell's contents. If the sort indicator is positioned on the right:
QHeaderView::up-arrow, QHeaderView::down-arrow { position: right; }
it overlaps the rest of the content if there isn't enough space to the right. This is usually the text. An interesting peculiarity is that setting its position to
left
orbottom
results in positioning it to theright
.Any suggestions here how to fix this as well using some standardized approach are welcome as well. The brute force one is known - draw it yourself and calculate the size hint yourself.
-
What Qt version do you use? Afaik this should be fixed in 5.11: https://bugreports.qt.io/browse/QTBUG-56457?jql=text ~ "qheaderview font-size"
btw: Searching in the bug tracker before writing such a long text would have saved you some time I guess :) -
What Qt version do you use?
Qt 5.10.1.
Afaik this should be fixed in 5.11: https://bugreports.qt.io/browse/QTBUG-56457?jql=text ~ "qheaderview font-size"
In vain, using Qt 5.11 it isn't:
Searching in the bug tracker before writing such a long text would have saved you some time I guess :)
Correct. I've only searched in the forum and Google but neither provided the desired result, presumably due to not well composed query. Thought of filing it as a bug but decided to ask first.
-
Let's try to nail where the problem is. Try using a
QStandardItemModel
in a tableview and useQStandardItemModel::setHeaderData(i,Qt::Horizontal,yourFont,Qt::FontRole)
whereyourFont
is aQFont
to see if it resizes correctly that way.Also, if you could provide a minimal example to reproduce it would be very helpful
-
@VRonin : I'm pretty sure it's a stylesheet problem. There is a similar bug around in the bugtracker and I think they are all closed in 5.12.
But yes, we need a minimal example.