如何在 wxpython 中调整我的工具提示? [英] How to tweak my tooltips in wxpython?

查看:37
本文介绍了如何在 wxpython 中调整我的工具提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图添加一个工具提示来显示被截断的 ObjectListView 的完整内容,直到它内置了这样一个功能:

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:

我尝试使用 wx.TipWindow、wx.PopupWindow 和 SuperToolTip 制作自己的工具提示,但没有一个看起来像这个原生".

I tried making my own tool tips using wx.TipWindow, wx.PopupWindow and SuperToolTip, but none of them looked as 'native' as this one.

虽然 我知道这篇 wiki 文章 据说为截断的 wx 启用了工具提示.Listrctrls,我真的不明白如何让它工作.我还希望它仅在某些内容被截断时才有效,而我希望能够使用它来显示更多信息.

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.

我猜 SuperToolTip 很接近,但是当您删除标题"时,它会在顶部留下空白空间,而不是将文本居中放置在工具提示的中间并使其适合.

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.

我尝试查看 ObjectListView、SuperToolTip 和 wxpython 的源代码,试图找出工具提示是如何创建的,但我无法真正找到实现它的低级部分.

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.

那么我该如何调整工具提示,使其看起来更像原生工具提示?

生成我当前弹出窗口的代码是:

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)

推荐答案

即使无法从头开始创建和弹出原生工具提示,您仍然可以在创建时为整个 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.

    self.lc = wx.ListCtrl(self, style=wx.LC_REPORT)
    # ...
    self.lc.Bind(wx.EVT_MOTION, self.OnMouseMotion)

def OnMouseMotion(self, evt):
    pos = self.lc.ScreenToClient(wx.GetMousePosition())
    item_index, flag = self.lc.HitTest(pos)
    tip = self.lc.GetToolTip()

    if flag == wx.LIST_HITTEST_ONITEMLABEL:
        tip.SetTip('Some information about ' + self.lc.GetItemText(item_index))
    else:
        tip.SetTip('')

    evt.Skip()

这篇关于如何在 wxpython 中调整我的工具提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆