如何在 wxpython 中调整我的工具提示?
我试图添加一个工具提示来显示截断的 ObjectListView 的完整内容,直到发现它内置了这样的功能:
我尝试使用 wx.TipWindow、wx.PopupWindow 和 SuperToolTip 制作自己的工具提示,但没有一个看起来像这个那样“原生”。
虽然我知道这篇 wiki 文章 据称可以启用截断的 wx.Listrctrls 的工具提示,我真的不明白如何让它工作。我还希望它仅在某些内容被截断时才起作用,而我希望能够使用它来显示更多信息。
我猜 SuperToolTip 很接近,但是当您删除“标题”时,它会在顶部留下空白空间,而不是将文本置于工具提示中间并使其适合。
我尝试查看 ObjectListView、SuperToolTip 和 wxpython 的源代码,试图找到工具提示是如何创建的,但我无法真正找到实现它的低级部分。
那么我如何调整工具提示,使它们看起来更像本机工具提示?
生成当前弹出窗口的代码是:
text = "I'm a popup"
class PopUp(wx.TipWindow):
def __init__(self, parent, text):
wx.TipWindow.__init__(self, parent, text)
class PopUp2(wx.PopupWindow):
def __init__(self, parent, text):
wx.PopupWindow.__init__(self, parent)
st = wx.StaticText(self, parent, text)
# Import `from agw import supertooltip as STT`
popup3 = STT.SuperToolTip(text)
I was trying to add a tooltip to show the full content of a truncated ObjectListView, until it turned out it had such a feature built-in:
I tried making my own tool tips using wx.TipWindow, wx.PopupWindow and SuperToolTip, but none of them looked as 'native' as this one.
While I'm aware of this wiki article that supposedly enables the tooltip for truncated wx.Listrctrls, I didn't really understand how to get it working. I also expect that it only works when something is truncated, whereas I'd like to be able to use it to display some more information.
I guess the SuperToolTip comes close, but when you remove the 'header' it leaves it with empty space at the top, rather than centering the text in the middle of the tooltip and making it fit.
I tried looking through the source code of ObjectListView, SuperToolTip and wxpython to try and find how tooltips are being created, but I can't really find the low level parts that make it happen.
So how can I tweak tooltips so they look more like native tooltips?
The code to generate my current popups was:
text = "I'm a popup"
class PopUp(wx.TipWindow):
def __init__(self, parent, text):
wx.TipWindow.__init__(self, parent, text)
class PopUp2(wx.PopupWindow):
def __init__(self, parent, text):
wx.PopupWindow.__init__(self, parent)
st = wx.StaticText(self, parent, text)
# Import `from agw import supertooltip as STT`
popup3 = STT.SuperToolTip(text)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我们是否有办法创建本机 Win7 工具提示,正如您所看到的 wx.TipWindow 看起来像旧版本 Windows 中的工具提示一样,因此我们可能应该使用一些较新的 API。请在 trac.wxwidgets.org 上创建票证以进行确认,或者如果我目前没有想到的其他方式无法实现,则可以请求更改。
I'm not sure if we have a way to create a native Win7 tooltip yet, as you've seen wx.TipWindow looks like the tooltips from older versions of Windows, so there are probably some newer APIs that we should be using instead. Please create a ticket at trac.wxwidgets.org to find out for sure or to request the change if it's not possible some other way that I'm not thinking of at the moment.
即使您无法从头开始创建并弹出原生工具提示,您仍然可以在创建时为整个 ListCtrl 分配一个工具提示,然后根据鼠标指针下的项目将文本更改为您想要的任何内容。它不像 ObjectListView 那样将工具提示整齐地放置在列表项上,但我认为它仍然可以满足您的要求。
Even if you can't create and pop up a native tooltip from scratch, you can still assign the entire ListCtrl a tooltip when you create it, and then change the text to whatever you want based on the item under the mouse pointer. It doesn't position the tooltip neatly over the list item like ObjectListView does, but I think it still accomplishes what you're asking.