PDA

View Full Version : How to make only part of a button react on user actions based on graphical shape?



Evengard
13th January 2012, 02:04
The question is a bit difficult to explain, but I will try.

I have an image of a button:

http://i.stack.imgur.com/im6Pk.png


And I also have some animations of it, such as (gif with a single loop, reload it to view the animation!):

http://i.stack.imgur.com/RX3xX.gif

Also, I have some kind of a pattern:

http://i.stack.imgur.com/IiI9C.png

So, now the question: how to make the button react (for example on clicks/hower/etc) only when the mouse is INSIDE the black part of the pattern, and disallow such reactions when the mouse is out of the scope of this pattern? Without modifiyng the graphical files of course. And of course the pattern itself should be invisible.

I want to make that with help of C++ and Qt.

Just please indicate me at least the path, which functions/classes of Qt should I look for! Because now I am completely lost.

Lykurg
13th January 2012, 07:09
A simple solution would be to subclass QPushButton and reimp mousePressEvent. There you check if event->pos() is in the region of the black area. Only if true propagate the event to the base class.