Better way to make components (and children) draggable?


I’ve currently implemented a “lock” and “unlock” state to my application (via right-click pop up menu and keyboard shortcut) which enables users to unlock the gui panel, and drag / reposition components. The problem I was having is that child components of the component I was trying to drag were still clickable. For example, I have a class that has a few gui elements (2 drop down menus, a button…etc). When I would set that component to be draggable (using ComponentDragger), if I clicked over any of its children components, they would get triggered and I could not drag the component. If I however click outside of a child component, it dragged fine, with all children. Here is my hack to get around it. Basically, when my program goes into the unlock/draggable mode, it calls setDraggable on my objects, and if it is in edit/drag mode, it set setInterceptsMouseClicks to false for all children components, then back to true when the gui editing panel is locked… is there a better way? Should I be creating some sort of intermediary to handle the managing of all my object placement and dragging whatnot? Thanks!

[code]void SensorRecorder::setDraggable(bool _drag){
drag = _drag;

	for(int i = 0; i < this->getNumChildComponents(); i++){
		getChildComponent(i)->setInterceptsMouseClicks(false, false);	
	for(int i = 0; i < this->getNumChildComponents(); i++){
		getChildComponent(i)->setInterceptsMouseClicks(true, true);	



Another approach might be to have a invisible overlay components covering the child components and catching the clicks. Or even one big overlay on the whole thing.


Thanks for the reply-- that’s the other option I was considering. Making a class which automatically creates child overlay components, and putting that in my main program. I found an example from Haydxn a while back, but couldn’t get it working. I think I’ll give it another shot!



Haydxn’s editor class worked a charm! Got it working in about 5 minutes :slight_smile: Going to customize it a bit, but its really quite nice… thanks again for your help Jules, I’ve learned so much from you and the framework in the last few months!