Fix changing tooltip via wxToolTip::SetTip() in wxQt

Update the actual tool tip used by Qt and not just the internal variable
when SetTip() is called.

Also implement wxToolTip::SetWindow().

Closes https://github.com/wxWidgets/wxWidgets/pull/1175
This commit is contained in:
ali kettab
2019-01-24 15:54:32 +01:00
committed by Vadim Zeitlin
parent 3c369af2e6
commit 84fc5c1714
4 changed files with 25 additions and 6 deletions

View File

@@ -10,7 +10,8 @@
#include "wx/object.h" #include "wx/object.h"
class wxWindow; class WXDLLIMPEXP_FWD_CORE wxWindow;
class WXDLLIMPEXP_CORE wxToolTip : public wxObject class WXDLLIMPEXP_CORE wxToolTip : public wxObject
{ {
public: public:

View File

@@ -173,6 +173,11 @@ public:
virtual QScrollArea *QtGetScrollBarsContainer() const; virtual QScrollArea *QtGetScrollBarsContainer() const;
#if wxUSE_TOOLTIPS
// applies tooltip to the widget.
virtual void QtApplyToolTip(const wxString& text);
#endif // wxUSE_TOOLTIPS
protected: protected:
virtual void DoGetTextExtent(const wxString& string, virtual void DoGetTextExtent(const wxString& string,
int *x, int *y, int *x, int *y,

View File

@@ -43,12 +43,16 @@
wxToolTip::wxToolTip(const wxString &tip) wxToolTip::wxToolTip(const wxString &tip)
{ {
m_window = NULL;
SetTip(tip); SetTip(tip);
} }
void wxToolTip::SetTip(const wxString& tip) void wxToolTip::SetTip(const wxString& tip)
{ {
m_text = tip; m_text = tip;
if ( m_window )
m_window->QtApplyToolTip(m_text);
} }
const wxString &wxToolTip::GetTip() const const wxString &wxToolTip::GetTip() const
@@ -59,6 +63,7 @@ const wxString &wxToolTip::GetTip() const
void wxToolTip::SetWindow(wxWindow *win) void wxToolTip::SetWindow(wxWindow *win)
{ {
wxCHECK_RET(win != NULL, "window should not be NULL");
m_window = win; m_window = win;
wxMISSING_FUNCTION(); m_window->QtApplyToolTip(m_text);
} }

View File

@@ -951,14 +951,22 @@ void wxWindowQt::DoMoveWindow(int x, int y, int width, int height)
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
void wxWindowQt::QtApplyToolTip(const wxString& text)
{
GetHandle()->setToolTip(wxQtConvertString(text));
}
void wxWindowQt::DoSetToolTip( wxToolTip *tip ) void wxWindowQt::DoSetToolTip( wxToolTip *tip )
{ {
if ( m_tooltip == tip )
return;
wxWindowBase::DoSetToolTip( tip ); wxWindowBase::DoSetToolTip( tip );
if ( tip != NULL ) if ( m_tooltip )
GetHandle()->setToolTip( wxQtConvertString( tip->GetTip() )); m_tooltip->SetWindow(this);
else else
GetHandle()->setToolTip( QString() ); QtApplyToolTip(wxString());
} }
#endif // wxUSE_TOOLTIPS #endif // wxUSE_TOOLTIPS