- m_fileMetaDataToolTip->move(x, y);
- m_fileMetaDataToolTip->show();
+ if (!updateWidth && !updateHeight) {
+ // Default case: There is enough room below and right from the mouse
+ // pointer and the tooltip can be positioned there.
+ m_fileMetaDataToolTip->move(x, y);
+ m_fileMetaDataToolTip->show();
+ } else {
+ // There is not enough room to show the tooltip at the mouse pointer and
+ // it must be moved left or upwards. In this case the size hint of the
+ // tooltip is not sufficient and the size after opening must be respected.
+ // To prevent a flickering, the tooltip is first opened outside the visible
+ // desktop are and moved afterwards.
+ m_fileMetaDataToolTip->move(desktop.right() + 1, desktop.bottom() + 1);
+ m_fileMetaDataToolTip->show();
+
+ const QSize shownSize = m_fileMetaDataToolTip->size();
+ const int xDiff = updateWidth ? shownSize.width() - size.width() : 0;
+ const int yDiff = updateHeight ? shownSize.height() - size.height() : 0;
+ m_fileMetaDataToolTip->move(x - xDiff, y - yDiff);
+ }