How to Make a Qt Widget Transparent to Mouse Events

Before I come up with the current title of this post, I thought of many other titles including:

  • How to send mouse clicks and events to a Qt widget behind another widget
  • How to make a Qt widget ignore mouse events
  • and so on …

Although the answer was very straightforward and easy, I struggled a lot with it since I wasn’t asking the right question.


Simply put, I was creating a widget over another widget, but I still wanted the widget behind to answer to all mouse clicks and events. In case you are facing the same dilemma, here’s the code you need to use:

theWidget->setAttribute(Qt::WA_TransparentForMouseEvents);

Any widget with this attribute will become “transparent” to all mouse events as the name suggests, and yes, that is how I came up with this title.

Here’s the description of this attribute from Qt Documentation:

When enabled, this attribute disables the delivery of mouse events to the widget and its children. Mouse events are delivered to other widgets as if the widget and its children were not present in the widget hierarchy; mouse clicks and other events effectively "pass through" them. This attribute is disabled by default.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.