summaryrefslogtreecommitdiff
path: root/vcl/qt5
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2022-04-12 00:29:56 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2022-04-12 14:09:00 +0200
commitaf6dd54d53eee0d0de1164bff0a77c6b433b3935 (patch)
tree01346b6ab1e9b6c9b94aef8d36de3499b5345d05 /vcl/qt5
parentea68de2968c0dbcd8e7549435e829db06795c16d (diff)
tdf#148115 Qt handle tooltips via event loop
Instead of calling QToolTip::showText directly from LO, this defers showing the tooltip to the QEvent processing, which takes the tooltip timeouts into account. So tooltips are shown with a slight delay, therefore they happen less fast on mouse move, reducing / avoiding artifacts of fast changing windows. This unfortunately comes with yet an other hack in the area of our fake popup windows... New handling is based on the code of the Qt Tool Tips example. Change-Id: I42634ad36dd12171c30f52f07a02a88d3c48a718 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132841 Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Tested-by: Jenkins
Diffstat (limited to 'vcl/qt5')
-rw-r--r--vcl/qt5/QtFrame.cxx8
-rw-r--r--vcl/qt5/QtWidget.cxx19
2 files changed, 25 insertions, 2 deletions
diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx
index 91361311d60e..440cd8048d76 100644
--- a/vcl/qt5/QtFrame.cxx
+++ b/vcl/qt5/QtFrame.cxx
@@ -173,7 +173,12 @@ QtFrame::QtFrame(QtFrame* pParent, SalFrameStyleFlags nStyle, bool bUseCairo)
m_pTopLevel->setFocusProxy(m_pQWidget);
}
else
+ {
m_pQWidget = new QtWidget(*this, aWinFlags);
+ // from Qt's POV the popup window doesn't have the input focus, so we must force tooltips...
+ if (isPopup())
+ m_pQWidget->setAttribute(Qt::WA_AlwaysShowToolTips);
+ }
QWindow* pChildWindow = windowHandle();
connect(pChildWindow, &QWindow::screenChanged, this, &QtFrame::screenChanged);
@@ -859,7 +864,8 @@ bool QtFrame::ShowTooltip(const OUString& rText, const tools::Rectangle& rHelpAr
QRect aHelpArea(toQRect(rHelpArea));
if (QGuiApplication::isRightToLeft())
aHelpArea.moveLeft(maGeometry.nWidth - aHelpArea.width() - aHelpArea.left() - 1);
- QToolTip::showText(QCursor::pos(), toQString(rText), m_pQWidget, aHelpArea);
+ m_aTooltipText = rText;
+ m_aTooltipArea = aHelpArea;
return true;
}
diff --git a/vcl/qt5/QtWidget.cxx b/vcl/qt5/QtWidget.cxx
index 612682ae987f..33320c577f94 100644
--- a/vcl/qt5/QtWidget.cxx
+++ b/vcl/qt5/QtWidget.cxx
@@ -42,6 +42,7 @@
#include <QtGui/QTextCharFormat>
#include <QtGui/QWheelEvent>
#include <QtWidgets/QMainWindow>
+#include <QtWidgets/QToolTip>
#include <QtWidgets/QWidget>
#include <cairo.h>
@@ -562,7 +563,7 @@ bool QtWidget::handleKeyEvent(QtFrame& rFrame, const QWidget& rWidget, QKeyEvent
return bStopProcessingKey;
}
-bool QtWidget::handleEvent(QtFrame& rFrame, const QWidget& rWidget, QEvent* pEvent)
+bool QtWidget::handleEvent(QtFrame& rFrame, QWidget& rWidget, QEvent* pEvent)
{
if (pEvent->type() == QEvent::ShortcutOverride)
{
@@ -589,6 +590,22 @@ bool QtWidget::handleEvent(QtFrame& rFrame, const QWidget& rWidget, QEvent* pEve
ButtonKeyState::Pressed))
return true;
}
+ else if (pEvent->type() == QEvent::ToolTip)
+ {
+ // Qt's POV on focus is wrong for our fake popup windows, so check LO's state.
+ // Otherwise Qt will continue handling ToolTip events from the "parent" window.
+ const vcl::Window* pFocusWin = Application::GetFocusWindow();
+ if (!rFrame.m_aTooltipText.isEmpty() && pFocusWin
+ && pFocusWin->GetFrameWindow() == rFrame.GetWindow())
+ QToolTip::showText(QCursor::pos(), toQString(rFrame.m_aTooltipText), &rWidget,
+ rFrame.m_aTooltipArea);
+ else
+ {
+ QToolTip::hideText();
+ pEvent->ignore();
+ }
+ return true;
+ }
return false;
}