diff options
author | Liang Qi <liang.qi@qt.io> | 2018-10-26 10:28:24 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2018-10-26 10:28:24 +0000 |
commit | 00b2e45a97205975ee91aa43f00e3dbef1a8907b (patch) | |
tree | ed44e50bc893e87434d72470c2c809b1fb34de72 /src/widgets/kernel/qtooltip.cpp | |
parent | 9cd527bc1f384926985d63c741641316a66f17a4 (diff) | |
parent | e28e91ae99b8c3859899e04cc9370534c7c7b86d (diff) |
Merge "Merge remote-tracking branch 'origin/5.12' into dev" into refs/staging/dev
Diffstat (limited to 'src/widgets/kernel/qtooltip.cpp')
-rw-r--r-- | src/widgets/kernel/qtooltip.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp index 8c5573d3a3..2e6575c163 100644 --- a/src/widgets/kernel/qtooltip.cpp +++ b/src/widgets/kernel/qtooltip.cpp @@ -229,12 +229,17 @@ void QTipLabel::updateSize(const QPoint &pos) ++extra.rheight(); QSize sh = sizeHint(); if (wordWrap()) { - const QRect screenRect = QGuiApplication::screenAt(pos)->geometry(); - if (sh.width() > screenRect.width()) { - // Try to use widely accepted 75chars max length or 80% of the screen width else. - // See https://en.wikipedia.org/wiki/Line_length - sh.setWidth(qMin(fm.averageCharWidth() * 75, static_cast<int>(screenRect.width() * .8))); - sh.setHeight(heightForWidth(sh.width())); + QScreen *screen = QGuiApplication::screenAt(pos); + if (!screen) + screen = QGuiApplication::primaryScreen(); + if (screen) { + const qreal screenWidth = screen->geometry().width(); + if (sh.width() > screenWidth) { + // Try to use widely accepted 75chars max length or 80% of the screen width else. + // See https://en.wikipedia.org/wiki/Line_length + sh.setWidth(qMin(fm.averageCharWidth() * 75, static_cast<int>(screenWidth * .8))); + sh.setHeight(heightForWidth(sh.width())); + } } } resize(sh + extra); |