Robin Dunn wrote:
>
> I am using a wx.combo.ComboCtrl in the DateEditorAndPicker
> control discussed recently.
>
> I want to add a ToolTip to the Button portion of the control,
> explaining that the user can press F4 or Space to open the Calendar.
>
[...]
>
> Is there a way to get a reference to the underlying Button?
IIRC, whether or not there is a real wx.Button there is an
implementation detail that can vary by platform and by style of
comboctrl. It may just be using the native renderer to draw a
button-like image on the combo widget instead.
I tried to read the source on the wxWidgets site. I don't understand much of
it, but it seems that there is *something* there, called m_btn.
Here is a snippet from combo.h -
// get the dropdown button which is part of the combobox
// note: its not necessarily a wxButton or wxBitmapButton
wxWindow *GetButton() const { return m_btn; }
Here is a snippet from combocmn.cpp -
#if wxUSE_TOOLTIPS
void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip)
{
wxControl::DoSetToolTip(tooltip);
// Set tool tip for button and text box
if ( tooltip )
{
const wxString &tip = tooltip->GetTip();
if ( m_text ) m_text->SetToolTip(tip);
if ( m_btn ) m_btn->SetToolTip(tip);
}
else
{
if ( m_text ) m_text->SetToolTip( NULL );
if ( m_btn ) m_btn->SetToolTip( NULL );
}
}
#endif // wxUSE_TOOLTIPS
So not only is there a button of some sort, but one should be able to set a
tooltip on it.
I tried to do it the hard way, but I hit a problem. I can calculate which
portion of the control represents the button, and if the mouse hovers over
it I can set a tooltip. When the mouse leaves the button, I want to clear
the tooltip. This works on msw, but on gtk2 the tooltip remains, no matter
what I do. I have tried setting the tooltip to an empty string, and to None,
but it makes no difference. The result is that, once it has been displayed
once, if the user hovers over the button *or* the text control part of the
control, the tooltip is displayed.
Sorry to be a nuisance, Robin, but please can you have another look at this.
It looks as if GetButton() *should* return a reference to the button portion
of the control, whether it is a wx.Button or not, and it looks as if one
should be able to set a tooltip on it.
Thanks
Frank
···
On 7/13/10 12:03 AM, Frank Millman wrote: