Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to hover over a label to display text

How to hover over a label to display text

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 4.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LT-K101
    wrote on last edited by
    #1

    Hi, Please I'm really struggling on how to hover over a label to display text. I have seen some tutorials on how to hover over a pushButton to change background color. Any assistance will be appreciated. Thanks in advance.

    JonBJ 1 Reply Last reply
    0
    • L LT-K101

      Hi, Please I'm really struggling on how to hover over a label to display text. I have seen some tutorials on how to hover over a pushButton to change background color. Any assistance will be appreciated. Thanks in advance.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @LT-K101
      What do you actually mean by "hover over a label to display text."? You can just call QLabel::setToolTip("Some text") to display text when hovering.

      L 1 Reply Last reply
      2
      • JonBJ JonB

        @LT-K101
        What do you actually mean by "hover over a label to display text."? You can just call QLabel::setToolTip("Some text") to display text when hovering.

        L Offline
        L Offline
        LT-K101
        wrote on last edited by LT-K101
        #3

        @JonB I tried the code below and it returns an empty toolTip with no message.

        self.ui.label_83.setToolTip("Name: Jane " )
        

        What I actaully want to achieve is when I hover on a profile image the name of the person should be displayed from database. I can see the name from database with print(person[1]). However when I tried the syntax below I get an empty toolTip when I hover over the label containing the image. I think I might be doing something wrong.

        self.ui.label_83.setToolTip(str(person[1]))
        
        JonBJ 1 Reply Last reply
        0
        • L LT-K101

          @JonB I tried the code below and it returns an empty toolTip with no message.

          self.ui.label_83.setToolTip("Name: Jane " )
          

          What I actaully want to achieve is when I hover on a profile image the name of the person should be displayed from database. I can see the name from database with print(person[1]). However when I tried the syntax below I get an empty toolTip when I hover over the label containing the image. I think I might be doing something wrong.

          self.ui.label_83.setToolTip(str(person[1]))
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @LT-K101
          Since there are many examples on the web of using setToolTip() on a QLabel I don't know what to say. If you leave your labels named label_83 it's hardly to easy to verify which one you are setting it on....

          You can/must set the tooltip which comes from a database at the time the correct data is available. For your setToolTip(str(person[1])) I don't know when that is, but you do.

          An alternative approach to set a dynamic tooltip, i.e. one whose text is not set/evaluated until the time the user hovers instead of in advance, is shown in https://stackoverflow.com/a/21869703, but they may require subclassing QLabel which you are probably not set up for. In any case it still uses QLabel::setToolTip().

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved