]> cloud.milkyroute.net Git - dolphin.git/commit
Port away from deprecated QFontMetrics::width()
authorElvis Angelaccio <elvis.angelaccio@kde.org>
Thu, 28 May 2020 20:40:57 +0000 (22:40 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Fri, 29 May 2020 23:23:55 +0000 (23:23 +0000)
commitb65576a131eb59eaab4d33af830bdb2d2f9fde9f
tree099c4b343ec5519fffa733ecebedf34ba723c8ca
parent7df39255a6a019d98e240261661c70866ce25151
Port away from deprecated QFontMetrics::width()

While the documention says to port to QFontMetrics::horizontalAdvance(),
what we actually need is not the horizontal advance, but the width of
the text. So we need to port to QFontMetrics::boundingRect().width().

Quoting from https://kdepepo.wordpress.com/2019/08/05/about-deprecation-of-qfontmetricswidth/:

"Since it was not clear from the confusingly named function QFontMetrics::width()
that it actually returned the horizontal advance, instead of the bounding width,
this method is now obsolete.
You must port to either QFontMetrics::horizontalAdvance() or QFontMetrics::boundingRect().width().

Please make sure you are aware of the difference, and do not port
blindly. I am pretty sure that in most cases
QFontMetrics::boundingRect() is what you want, unless you are writing
custom text shaping/layouting code. Using the wrong function can cause
clipped text or text that suddenly wraps to the next line despite
calculating the width that it needs."
src/kitemviews/kstandarditemlistwidget.cpp