[Solved] Overlapping Widgets input problems



  • Hi everybody, I have run into a little problem concerning overlapping widgets. I have a map of the world where each state is a widget inheriting from Qlabel and implementing a clicked() signal, I set up the mousePressEvent this way:
    @if (this->isEnabled() && event->button()==Qt::LeftButton){
    QImage immagine=this->pixmap()->toImage();
    QRgb colore_pixel=immagine.pixel(event->pos());
    if (colore_pixel==QColor(0, 0, 0, 0).rgba()) return;
    emit(clicked(Identita));
    }@
    so that it responds to clicks only if you actually clicked on the state and not in any other (transparent) area of the pixmap. Everything works fine but I have a problem in the areas where two of this widgets overlaps since only the one on top responds to the mouse click.
    For example:
    China is on top of Mongolia, but since a wide transparent area of the china's pixmap overlaps the area of mongolia when clicked on this state only the china's mousePressEvent is called and not the mongolia's one too.
    How can I call the event for all the widget under the mouse location and not just the top one?
    Thanks in advance for support
    Regards
    Luca



  • Well, this is probably far too late to help Luca, but for any others looking for the "right" answer (like me :-) you should probably assign a Mask to your Widget. See this "blog post":http://blog.qt.digia.com/blog/2006/05/27/mouse-event-propagation/ and the QWidget::setMask documentation.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.