可以轻松完成的一件事是使用 Insert -> Comment 将 cmets 添加到每个单元格。
然后,例如,如下图所示选择单元格 A5 并转到 数据 -> 有效性。将单元格范围源设置为 A1 到 A3。
另外,使用标签控件的工具提示示例位于https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=57791。
通过编写事件侦听器,可以找到更接近您在问题中描述的解决方案。 XListBox 有一个名为 itemStateChanged 的事件。可能不是显示工具提示,而是在此事件发生时在文本框中显示信息。
编辑:
这是显示我的想法的示例代码。使用 APSO 运行showdlg()。
import uno
import unohelper
from com.sun.star.awt import XItemListener
Items = [
("Item 1", "This is the first item"),
("Item 2", "This is the second item"),
("Item 3", "This is the third item"),
]
def showdlg():
doc = XSCRIPTCONTEXT.getDocument()
dlg = TooltipDialog(doc)
dlg.show()
class TooltipDialog(XItemListener, unohelper.Base):
def __init__(self, doc):
self.parent = doc.CurrentController.Frame.ContainerWindow
self.dlg = None
self.label = None
def show(self):
toolkit = self.parent.getToolkit()
ctx = uno.getComponentContext()
smgr = ctx.ServiceManager
model = smgr.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialogModel", ctx)
dialog = smgr.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialog", ctx)
model.setPropertyValue("PositionX", 100)
model.setPropertyValue("PositionY", 100)
model.setPropertyValue("Width", 200)
model.setPropertyValue("Height", 75)
model.setPropertyValue("Title", "Tooltip Listbox")
listbox = model.createInstance(
"com.sun.star.awt.UnoControlListBoxModel")
listbox.setPropertyValue("PositionX", 20)
listbox.setPropertyValue("PositionY", 10)
listbox.setPropertyValue("Width", 40)
listbox.setPropertyValue("Height", 20)
listbox.setPropertyValue("Dropdown", True)
listbox.setPropertyValue("Name", "ListBox1")
for pos in range(len(Items)):
listbox.insertItemText(pos, Items[pos][0])
model.insertByName("ListBox1", listbox)
label = model.createInstance(
"com.sun.star.awt.UnoControlFixedTextModel")
label.setPropertyValue("PositionX", 70)
label.setPropertyValue("PositionY", 10)
label.setPropertyValue("Width", 100)
label.setPropertyValue("Height", 20)
label.setPropertyValue("Name", "Label1")
label.setPropertyValue("Label", "(Please select an item.)")
model.insertByName("Label1", label)
dialog.setModel(model)
control = dialog.getControl("ListBox1")
control.addItemListener(self)
self.label = dialog.getControl("Label1")
dialog.createPeer(toolkit, None)
self.dlg = dialog
self.dlg.execute()
self.dlg.dispose()
def itemStateChanged(self, itemEvent):
"""XItemListener event handler."""
pos = itemEvent.Source.SelectedItemPos
description = Items[pos][1]
self.label.setText(description)
您可能会注意到,该示例不包含任何特殊格式。例如,将其更改为将标签修改为黄色 3-D 框应该很简单。此外,该示例可以使用threads 显示在短时间内消失的消息。它仍然不是一个真正的工具提示,但如果这对您很重要的话,它可以让它看起来和工作起来很像。
可以使用电子表格lookup 函数实现类似的解决方案,而无需任何宏。文本将出现在一个单元格中,而不是单独的对话框中,并且单元格值将根据数据有效性结果计算。这样就不会在外观方面提供太大的灵活性,但它应该能够毫无问题地显示描述。