Mouse events don't work [user error, not a bug]


#1

I just started using Juce GUI library for c++. I am trying to create custom listbox where I will display file names later. Now I need to change the background color of the rows of this custom listbox when mouse is in/out/clicked. The problem is that MouseEnter(), MouseExit() and MouseUp() don’t work. Here is the code:

class LeftExplorerItem : public Component, public MouseListener {

public:

LeftExplorerItem(String name = "LeftExplorerItem") : Component(name), isActive(false) {

	addMouseListener(this, true);

}

void paint(Graphics& g) override {

	if (!isActive) g.setColour(Colour(40, 40, 40));
	else g.setColour(Colour(150, 190, 255));
	g.fillRoundedRectangle(2, 2, getWidth() - 4, getHeight() - 4, 4);

	

	g.setColour(Colours::white);
	g.drawText("Frame #", 40, 0, 100, 25, Justification::centredLeft);

	

}

void mouseEnter(const MouseEvent& event) override {
	AlertWindow("", "", AlertWindow::AlertIconType::InfoIcon);
	isActive = true;

}

void mouseExit(const MouseEvent& event) override {

	isActive = false;

}

void mouseUp(const MouseEvent& event) override {
	AlertWindow("", "click", AlertWindow::AlertIconType::InfoIcon);
}

void resized() override {

}

private:

bool isActive;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LeftExplorerItem)
};

This is just the class for each item of my custom listbox. Keep in mind that everything appears okay (listbox, all listbox items, etc) the only problem is that mouse events never get triggered. What is missing here?


#2

Maybe you shouldn’t inherit from MouseListener since Component inherits from that already…


#3

I tried that. Still nothing.


#4

You definitely don’t need to derive from MouseListener since the Component base class already does… Is your Component being occluded by another Component?

Rail


#5

Okay, mouse events work great I just couldn’t see it because I didn’t repaint.