PDA

View Full Version : Do variables in QToolTip update automatically



dennisvz
23rd July 2020, 01:38
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):


self.ui.YourSSAmount.setToolTip(
'<span>Click Reports/Social Security to see your<br>SS income at each start age'
'<br><br>Your inf adj FRA amt at age {}:&nbsp;&nbsp;${:,.0f}'
'<br>Age adjustment:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{:.0f}%'
'<br>SS Income at age {}:&nbsp;&nbsp;&nbsp;&nbsp;${:,.0f}</span>'.format(
self.generator.YouSSStartAge, self.generator.your_new_FRA_amt,
self.generator.SS66.get(self.generator.YouSSStartA ge, 1.32) * 100, self.generator.YouSSStartAge,
self.generator.YourSSAmount))

Do variables not update automatically in a QToolTip (variables update automatically when contained in a QMessageBox, for example)???

d_stranz
23rd July 2020, 16:38
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.