Results 1 to 4 of 4

Thread: Turn link Invisible in QLabel?

  1. #1
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Turn link Invisible in QLabel?

    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

  2. #2
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default Re: Turn link Invisible in QLabel?

    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.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Turn link Invisible in QLabel?

    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:
    Qt Code:
    1. // text is hidden button button still occupies space
    2. label->setStyleSheet("QLabel { color: rgba(0, 0, 0, 0); } ");
    3.  
    4. // text gets default rendering
    5. label->setStyleSheet("");
    To copy to clipboard, switch view to plain text mode 
    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.

  4. #4
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default Re: Turn link Invisible in QLabel?

    Or simply setting the QColor transparency to 0 when not hovered.

Similar Threads

  1. Replies: 11
    Last Post: 5th May 2011, 15:05
  2. Turn off the underline when using a QLabel as a link
    By gmat4321 in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2010, 14:31
  3. Change color of a link in QLabel using Style Sheets?
    By codeslicer in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 12:00
  4. Replies: 2
    Last Post: 14th January 2008, 19:09
  5. QLabel link color
    By dragon in forum Qt Programming
    Replies: 1
    Last Post: 17th October 2007, 08:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.