How to detect mouse roll over or hover for TGPictureButton

Hello Rooters,

I’d like my gui to highlight some (picture) buttons when the user moves the mouse over that button.
I was hoping there would be a way to get the ‘mouse-entered’ and ‘mouse-left’ events for these buttons.

What is the best way to implement this functionality?

thanks very much,

Hi buddy,

You can use the ProcessedEvent(Event_t*) signal, as shown in this short macro:

#include "TGButton.h"
#include "TGFrame.h"
#include "TApplication.h"

void Action()
   printf("Test Button Pressed!\n");

void ProcessedEvent(Event_t *ev)
   // Slot called for every processed event

   TGPictureButton *button = (TGPictureButton *)gTQSender;
   if (ev->fType == kEnterNotify) {
   else if (ev->fType == kLeaveNotify) {

void EnterLeave()
   // Create a main frame
   TGMainFrame *main = new TGMainFrame(gClient->GetRoot(), 500, 200);

   TGPictureButton *exitbutton = new TGPictureButton(main, gClient->GetPicture("bld_exit.png"), "gApplication->Terminate(0)");
   main->AddFrame(exitbutton, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY,10,10,10,10));
   TGPictureButton *testbutton = new TGPictureButton(main, gClient->GetPicture("ed_goto.png"), "Action()");
   main->AddFrame(testbutton, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY,10,10,10,10));
   // connect the ProcessedEvent() signals from the buttons to our ProcessedEvent() slot
   exitbutton->Connect("ProcessedEvent(Event_t*)", 0, 0, "ProcessedEvent(Event_t*)");
   testbutton->Connect("ProcessedEvent(Event_t*)", 0, 0, "ProcessedEvent(Event_t*)");

   main->SetWindowName("Enter/Leave Test");
   main->MoveResize(100, 100, 200, 100);

Cheers, Bertrand.

Thank you very much, Bertrand.

You’re welcome :slight_smile: