diff --git a/src/ktooltipwidget.cpp b/src/ktooltipwidget.cpp --- a/src/ktooltipwidget.cpp +++ b/src/ktooltipwidget.cpp @@ -119,15 +119,16 @@ // It must be assured that: // - the content is fully visible // - the content is not drawn inside rect - - const QSize size = content->sizeHint(); - const int margin = q->style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth); + q->adjustSize(); + const QSize size = q->sizeHint(); const QRect screenGeometry = screen->geometry(); - + const int margin = q->style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth); + const bool hasRoomToLeft = (rect.left() - size.width() - margin >= screenGeometry.left()); const bool hasRoomToRight = (rect.right() + size.width() + margin <= screenGeometry.right()); const bool hasRoomAbove = (rect.top() - size.height() - margin >= screenGeometry.top()); const bool hasRoomBelow = (rect.bottom() + size.height() + margin <= screenGeometry.bottom()); + if (!hasRoomAbove && !hasRoomBelow && !hasRoomToLeft && !hasRoomToRight) { return QPoint(); } @@ -137,12 +138,13 @@ if (hasRoomBelow || hasRoomAbove) { x = qMax(screenGeometry.left(), rect.center().x() - size.width() / 2); if (x + size.width() >= screenGeometry.right()) { - x = screenGeometry.right() - size.width() + 1; + // Disallow negative x. Happens when rect is wider than screen. + x = qMax(screenGeometry.left(), screenGeometry.right() - size.width() + 1); } if (hasRoomBelow) { y = rect.bottom() + margin; } else { - y = rect.top() - size.height() - margin; + y = rect.top() - size.height() + margin; } } else { Q_ASSERT(hasRoomToLeft || hasRoomToRight);