【问题标题】:wxWidgets-how to add scrollbars in ListBox created by comboctrl widget in wxpythonwxWidgets-如何在 wxpython 中由 comboctrl 小部件创建的 ListBox 中添加滚动条
【发布时间】:2016-09-22 10:13:03
【问题描述】:

我已经使用 wxcomboctrl 创建了下拉列表。

self.Worker = wx.combo.ComboCtrl(self, -1, size=(250, -1), style=wx.CB_DROPDOWN)
self.testWorkloadComboCtrl = self.ListCtrlComboPopup()
self.worker.SetPopupControl(self.workerComboCtrl)


class ListCtrlComboPopup(wx.ListCtrl, wx.combo.ComboPopup):

    def __init__(self):
        self.PostCreate(wx.PreListCtrl())

        # Also init the ComboPopup base class.
        wx.combo.ComboPopup.__init__(self)


    def AddItem(self, txt):
        for t in txt:
            self.InsertStringItem(self.GetItemCount(), t)


    def OnMotion(self, evt):

        item, flags = self.HitTest(evt.GetPosition())
        if item >= 0:
            self.Select(item)
            self.curitem = item


    def OnLeftDown(self, evt):

        self.value = self.curitem
        self.Dismiss()


    # The following methods are those that are overridable from the
    # ComboPopup base class.

    def Init(self):
        """ This is called immediately after construction finishes.  You can
        use self.GetCombo if needed to get to the ComboCtrl instance. """

        self.value = -1
        self.curitem = -1


    def Create(self, parent):
        """ Create the popup child control. Return True for success. """

        wx.ListCtrl.Create(self, parent,
                       style=wx.LC_LIST|wx.LC_SINGLE_SEL|wx.SIMPLE_BORDER)
        self.Bind(wx.EVT_MOTION, self.OnMotion)
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)

        return True


    def GetControl(self):
        """ Return the widget that is to be used for the popup. """

        return self

    def SetStringValue(self, val):
        """ Called just prior to displaying the popup, you can use it to
    'select' the current item. """

        idx = self.FindItem(-1, val)

        if idx != wx.NOT_FOUND:
            self.Select(idx)


    def GetStringValue(self):
        """ Return a string representation of the current item. """

        if self.value >= 0:
            return self.GetItemText(self.value)

        return ""


    def OnPopup(self):
        """ Called immediately after the popup is shown. """

        wx.combo.ComboPopup.OnPopup(self)


    def OnDismiss(self):
        " Called when popup is dismissed. """

        wx.combo.ComboPopup.OnDismiss(self)

显示项目的下拉菜单,如带有水平滚动条的 2 或 3 列。

但我希望显示一个包含水平和垂直滚动条的项目列表。

我搜索了comboctrl的属性,但仍然不清楚comboctrl。

谁能给我建议。

【问题讨论】:

标签: wxpython wxwidgets


【解决方案1】:

尝试使用wx.LC_REPORT 样式而不是wx.LC_LIST。您还需要像使用 wx.LC_REPORT 样式的 wx.ListCtrls 一样创建列。

【讨论】:

  • 感谢您的回复。我不知道如何创建带有comboctrl列表弹出的列..你能告诉我单个列表的例子吗?
  • 当您创建 listctrl 时,您需要使用 AddColumn,就像您在不使用 comboctrl 的情况下单独使用 wx.ListCtrl 时一样。
猜你喜欢
  • 2012-05-12
  • 2020-02-22
  • 2018-05-02
  • 1970-01-01
  • 2021-11-15
  • 2011-03-06
  • 2022-12-03
  • 1970-01-01
相关资源
最近更新 更多