Results 1 to 2 of 2

Thread: Do variables in QToolTip update automatically

  1. #1
    Join Date
    Jan 2017
    Posts
    50
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Do variables in QToolTip update automatically

    I have a QToolTip on a QLineEdit that is set in the init. Within the text of tool tip are several variables.

    The issue: It seems like the variables are not updated automatically when they are changed by the program.

    For example, I hover the mouse over the line edit, and the tooltip and variable values are displayed. I the change something in the program that changes the variables, but when I go back and hover over the line edit again, the old variable values (instead of the new variable values) are displayed.

    I can fix the issue by moving the setting of the tooltip from the init to a function and calling it (essentially running .setToolTip) each time ANYTHING is changed in the program. But this seems a little weird.

    Here is the code to set the tooltip and variables (this is the code in the init):
    Qt Code:
    1. self.ui.YourSSAmount.setToolTip(
    2. '<span>Click Reports/Social Security to see your<br>SS income at each start age'
    3. '<br><br>Your inf adj FRA amt at age {}:&nbsp;&nbsp;${:,.0f}'
    4. '<br>Age adjustment:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{:.0f}%'
    5. '<br>SS Income at age {}:&nbsp;&nbsp;&nbsp;&nbsp;${:,.0f}</span>'.format(
    6. self.generator.YouSSStartAge, self.generator.your_new_FRA_amt,
    7. self.generator.SS66.get(self.generator.YouSSStartAge, 1.32) * 100, self.generator.YouSSStartAge,
    8. self.generator.YourSSAmount))
    To copy to clipboard, switch view to plain text mode 
    Do variables not update automatically in a QToolTip (variables update automatically when contained in a QMessageBox, for example)???

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,693
    Thanks
    259
    Thanked 752 Times in 742 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Do variables in QToolTip update automatically

    Seems to me that the tooltip text is created when it is initialized from the values the variables have -at that time-. If you want the tooltip to change as the variables change, you will have to re-format the text each time the variables change. Basically, your format statement creates a QString, and this QString is passed in as the tooltip text. The tooltip itself knows nothing about the variables used to create the string.

    The behavior you are seeing seems pretty reasonable to me - what if you -didn't- want the tooltip to change with the variables? If it was automatically updated each time, there would be no way to prevent that.

    In QMessageBox, I assume you are passing the text every time you post it (using one of the static methods - warning(), information() whatever). If you created a QMessageBox, set the text, and then just called show() and hide(), I'll bet you won't see updated text, just the text as it was when created.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    dennisvz (23rd July 2020)

Similar Threads

  1. Update a QGraphicsScene every x seconds automatically
    By Nezgal in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2013, 08:55
  2. Using CSS with Static QTooltip?
    By droneone in forum Qt Programming
    Replies: 0
    Last Post: 26th December 2012, 17:18
  3. Replies: 0
    Last Post: 12th July 2011, 09:19
  4. Replies: 5
    Last Post: 30th January 2010, 11:09
  5. QToolTip
    By suresh in forum Newbie
    Replies: 7
    Last Post: 6th September 2006, 16:00

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.