PDA

View Full Version : Turn link Invisible in QLabel?



ryugami
5th February 2012, 10:27
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 ;)

wayfaerer
6th February 2012, 01:40
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.

ChrisW67
6th February 2012, 02:39
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:


// text is hidden button button still occupies space
label->setStyleSheet("QLabel { color: rgba(0, 0, 0, 0); } ");

// text gets default rendering
label->setStyleSheet("");

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 .

Subclass QLabel. In the constructor(s) set the text hidden. In the enterEvent() unhide the text. In the leaveEvent() hide the text again.

wayfaerer
6th February 2012, 02:57
Or simply setting the QColor transparency to 0 when not hovered.