Gtk::Eventbox signal handling confusion while hover and click Gtk::Button

I want to display information about the Button as soon as the pointer hovers or enters the area inside the Button

Looked at this post Trigger checkbutton hover event from another widget

Tried replicated it

*.hpp

Gtk::Button *nButton;
Gtk::EventBox *nEventBox;
Gtk::Popover *nPopover;

bool onEnterButton(GdkEventCrossing *);
bool onExitButton(GdkEventCrossing *);
void onClick();

*.cpp

builder->get_widget("nEventBox",nEventBox);
nEventBox->add_events(Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK);
builder->get_widget("nButton",nButton);

builder->get_widget("nPopover",nPopover);
nPopover->set_relative_to(*nButton);
	nEventBox->signal_enter_notify_event().connect(sigc::mem_fun(*this,&ApplicationWindow::onEnterButton));
	nEventBox->signal_leave_notify_event().connect(sigc::mem_fun(*this,&ApplicationWindow::onExitButton));
nButton->signal_clicked().connect(sigc::mem_fun(*this,&ApplicationWindow::onClick));


bool ApplicationWindow::onEnterButton(GdkEventCrossing *event)
{	

	if (event->mode !=GDK_CROSSING_NORMAL)
	{
		return false;
	}
	nPopover->popup();
	return true;

}

bool ApplicationWindow::onExitButton(GdkEventCrossing *event)
{
	if (event->mode !=GDK_CROSSING_NORMAL)
	{
		return false;
	}
	nPopover->popdown();
	return true;
}

When cursor
Enter into the event box I can see the popover message
Leave the event box the popover messageremains doesn’t disappear

Only once I click inside the event box after entering it does the popover message disappear.

What am I doing wrong?

Please guide.

If you just want to show a text, setting the tooltip on the button should be the easies solution to that?

1 Like

Tooltip worked fine.
When I place a Gtk Image as an icon for Gtk Button, tooltip doesn’t come up when used for button or image, don’t know want is happening.

Have you tried setting the tooltip for the gtkimage as well?

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.