我在QLineEdit上有一个QToolTip,工具提示包含文本中的变量。工具提示代码包含在init中。问题是工具提示中的变量值在程序操作中更改时不会自动更新。例如,我将鼠标悬停在“线编辑”上,值显示在工具提示中。我更改了程序,返回到行编辑,工具提示中的变量没有更改
我可以通过将.setToolTip移动到一个函数并在每次程序中发生任何更改时调用该函数来解决这个问题,但这似乎有些过分,尤其是当99%的程序更改与此特定的工具提示无关时)
变量应该自动更新吗?以下是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 {}: ${:,.0f}'
'<br>Age adjustment: {:.0f}%'
'<br>SS Income at age {}: ${:,.0f}</span>'.format(
self.generator.YouSSStartAge, self.generator.your_new_FRA_amt,
self.generator.SS66.get(self.generator.YouSSStartAge, 1.32) * 100, self.generator.YouSSStartAge,
self.generator.YourSSAmount))
setToolTip方法获取文本并存储它,如果用于形成文本的任何变量发生更改,则不会收到通知
鉴于此,有两种可能的解决方案:
每次变量更改时更新工具提示:
覆盖工具提示以使用变量获取文本:
相关问题 更多 >
编程相关推荐