簡體   English   中英

工具提示對LibreOffice Calc下拉列表中的每個選項起作用

[英]Tooltips function to each option in a drop down list in LibreOffice Calc

我希望能夠向我的LibreOffice Calc文檔添加工具提示功能。

我有一個通過數據->有效性完成的下拉列表。 具有單元格范圍或列表。

如何盡可能簡單地在該下拉列表的每個選項上方插入工具提示文本?

我以前沒有寫過宏(工具->宏),我對Visual Basic,Pyhton或Java不熟悉。 我可以獲得幫助的任何安裝,插件和/或代碼段嗎?

例如:

1 (tooltip: this is option one)
2 (tooltip: this is option two)
3 (tooltip: option 3 this is)

我有Ubuntu 18.04。

可以輕松完成的一件事是使用Insert-> Comment將注釋添加到每個單元格。

然后,例如,選擇下圖所示的單元格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短時間后消失的消息。 它仍然不是真正的工具提示,但如果對您很重要,則可以使它看起來和工作起來很像。

可以使用電子表格查找功能來實現類似的解決方案,而無需任何宏。 文本將顯示在單元格中,而不是單獨的對話框中,並且將基於數據有效性結果來計算單元格值。 那將不會給它外觀帶來很大的靈活性,但是它應該能夠毫無問題地顯示說明。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM