Restore behavior for QToolTip not wrapping by default
This partially reverts 7a1d77b6e4
, which caused regressions
e.g. in Qt Creator.
The behavior of QToolTip for wrapping has been always special in
that wordWrap was enabled as soon as some HTML tags were
detected, while plain text was not wrapped. This is arguably bad API,
but by now a lot of applications depend on this exact behavior, so
I don't think it's worth to change this anymore.
What can be kept though is the check for overlong tooltips that do not
fit on the screen. In this case wrapping makes sense.
[ChangeLog][QtWidgets] Reverted a Qt 5.12.0 behavior change in
QToolTip that made plain tooltip text be wrapped automatically.
Fixes: QTBUG-72568
Change-Id: I6fa3e455f09cffaeb8ad1cdc6e81d71ae344dd34
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
66c9161d05
commit
17fe5fc128
@ -214,7 +214,6 @@ void QTipLabel::reuseTip(const QString &text, int msecDisplayTime, const QPoint
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
setWordWrap(true);
|
|
||||||
setText(text);
|
setText(text);
|
||||||
updateSize(pos);
|
updateSize(pos);
|
||||||
restartExpireTimer(msecDisplayTime);
|
restartExpireTimer(msecDisplayTime);
|
||||||
@ -227,19 +226,16 @@ void QTipLabel::updateSize(const QPoint &pos)
|
|||||||
// Make it look good with the default ToolTip font on Mac, which has a small descent.
|
// Make it look good with the default ToolTip font on Mac, which has a small descent.
|
||||||
if (fm.descent() == 2 && fm.ascent() >= 11)
|
if (fm.descent() == 2 && fm.ascent() >= 11)
|
||||||
++extra.rheight();
|
++extra.rheight();
|
||||||
|
setWordWrap(Qt::mightBeRichText(text()));
|
||||||
QSize sh = sizeHint();
|
QSize sh = sizeHint();
|
||||||
if (wordWrap()) {
|
|
||||||
QScreen *screen = QGuiApplication::screenAt(pos);
|
QScreen *screen = QGuiApplication::screenAt(pos);
|
||||||
if (!screen)
|
if (!screen)
|
||||||
screen = QGuiApplication::primaryScreen();
|
screen = QGuiApplication::primaryScreen();
|
||||||
if (screen) {
|
if (screen) {
|
||||||
const qreal screenWidth = screen->geometry().width();
|
const qreal screenWidth = screen->geometry().width();
|
||||||
if (sh.width() > screenWidth) {
|
if (!wordWrap() && sh.width() > screenWidth) {
|
||||||
// Try to use widely accepted 75chars max length or 80% of the screen width else.
|
setWordWrap(true);
|
||||||
// See https://en.wikipedia.org/wiki/Line_length
|
sh = sizeHint();
|
||||||
sh.setWidth(qMin(fm.averageCharWidth() * 75, static_cast<int>(screenWidth * .8)));
|
|
||||||
sh.setHeight(heightForWidth(sh.width()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resize(sh + extra);
|
resize(sh + extra);
|
||||||
|
Loading…
Reference in New Issue
Block a user