Hello,
I need an invisible item in my GUI with a hover event. I want to use and QLabel with a link in it but I need it to be invisible and have no idea how to do this. Any help will be greatly appreciated. thank you ;)
Printable View
Hello,
I need an invisible item in my GUI with a hover event. I want to use and QLabel with a link in it but I need it to be invisible and have no idea how to do this. Any help will be greatly appreciated. thank you ;)
Do you want the whole label to be invisible unless a user hovers over it? If so you can use setVisible(false) or hide(), then use setVisible(true) or show() to show it.
I assume the OP wants the widget to continue to occupy space in the layout: just be invisible. If you hide() the widget it disappears from the layout and will not see mouse events that could trigger its reappearance.
You could use the widget stylesheet to hide/unhide the foreground text of the label:
Alternatively, you could keep a copy of the text internally and set the widget text to "" to hide it, and restore the original text to show it. This approach may cause layout changes .Code:
// text is hidden button button still occupies space label->setStyleSheet("QLabel { color: rgba(0, 0, 0, 0); } "); // text gets default rendering label->setStyleSheet("");
Subclass QLabel. In the constructor(s) set the text hidden. In the enterEvent() unhide the text. In the leaveEvent() hide the text again.
Or simply setting the QColor transparency to 0 when not hovered.