I have do some research about QMouseEvents but I am stuck about passing a QMouseEvent to child widgets. I have a program with a structure like this :
MainWindow > DockWidget > WidgetList > WidgetTarget
MainWindow is parent of DockWidget etc... My primary goal is to know when I clicked in MainWindow and pass this QMouseEvent to WidgetTarget.
I read the doc about QMouseEvent and see the useful functions ignore() of QEvent but it does the contrary of what I want. The QMouseEvent is passed to the parent, so If I clik in WidgetTarget, the QMousseEvent will be pass to WidgetList.
So is there a way to pass a QMousseEvent to a child widget instead of its parent widget ? I have see some trick with the flag Qt::WA_TransparentForMouseEvents but I don't know if this is a correct way
EDIT : I will put some detail about the work in WidgetTarget with mousePressEvent(QMouseEvent *event). It basicaly to make a eyedropper. Here the code I have in mind :
void WidgetTarget::mousePressEvent(QMouseEvent *event)
{
if(eyeDropperActivated) //true when clicked on button eyedropper
{
QLabel *label = (QLabel*)MainWindow->childAt(event->x(),event->y());
QColor color; //Get the pixel value at x,y event from the QLabel pixmap
setColor(color) //Set the color parameter of WidgetTarget
}
}
I read your useful comments and yes I think It will be easy If I implement this code on MainWindow, but the eyedropper function is in WidgetTarget, so basically I have to find way to activate the eyedropper in WidgetTarget, check in the MainWindow if the eyedropper is activated, and send after to the WidgetTarget a signal with a QColor for example ?
Best Regards