Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Overlapping Widgets input problems
Forum Updated to NodeBB v4.3 + New Features

[Solved] Overlapping Widgets input problems

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #1

    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

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vaquita Tim
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved