Click with the mouse through a label
Solved
General and Desktop
-
hello to the whole community Qt Forum,
I would like to know if there is an option for qLabel that allows me to make it transparent only for the mouse, but in reality it must be seen; That is, this label contains a text, but I need to click below.
I hope I was clear
Thanks in advance :) -
Yes, you just need to reimplement the mouse click event and set
accepted
property to false.Example for widgets:
void MyLabel::mousePressEvent(QMouseEvent *event) { QLabel::mousePressEvent(event); event.setAccepted(false); } void MyLabel::mouseReleaseEvent(QMouseEvent *event) { QLabel::mouseReleaseEvent(event); event.setAccepted(false); }
QML example:
Label { MouseArea { onClicked: mouse.accepted = false } }
Brain-to-terminal, untested. But might work :-)
-
Hi,
IIRC, you can set the
Qt::WA_TransparentForMouseEvents
widget attribute and it should behave the way you'd like.