wxPython控件学习之UltimateListCtrl空间中使用ComboBox时,该控件一直在重绘的问题


例子:

#-*- coding: UTF-8 -*-
#-------------------------------------------------------------------------------
# Name:        模块mainFrame
# Purpose:     应用程序的主界面
#
# Author:      ankier
#
# Created:     16-12-2012
# Copyright:   (c) ankier 2012
# Licence:     <your licence>
#-------------------------------------------------------------------------------

try:
    from agw import floatspin as FS
except ImportError: # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.floatspin as FS

try:
    from agw import ultimatelistctrl as ULC
except ImportError: # if it's not there locally, try the wxPython lib.
    from wx.lib.agw import ultimatelistctrl as ULC
        
import wx
import sys
## @detail MainFrame主界面窗口类
class MainFrame(wx.Frame):
    def __init__(self):
        #重新定向wxpython的输出输入和错误输出到系统标准输入输出
        sys.stdin = sys.__stdin__
        sys.stdout = sys.__stdout__
        sys.stderr = sys.__stderr__
        wx.Frame.__init__(self, None, wx.ID_ANY,  'Ultimate list ctrl demo', pos=wx.DefaultPosition,
            size=(800, 600), style=wx.DEFAULT_FRAME_STYLE)
        self.CreateStatusBar()
        
        panel = wx.Panel(self, -1)           
        box = wx.FlexGridSizer(10, 2, 5, 5)
        
        button = wx.Button(panel, -1, 'Add')
        box.Add(button, 0, wx.ALIGN_CENTRE)
        button.Bind(wx.EVT_BUTTON, self.__OnAddClicked)
        
        self.listCtrls = ULC.UltimateListCtrl(panel, -1, size =(200, 100), style = ULC.ULC_MASK_TYPE, agwStyle = ULC.ULC_REPORT|ULC.ULC_HAS_VARIABLE_ROW_HEIGHT|ULC.ULC_NO_FULL_ROW_SELECT)
        self.listCtrls.InsertColumn(0, 'Name', ULC.ULC_FORMAT_CENTRE)
        self.listCtrls.InsertColumn(1, 'Selection', ULC.ULC_FORMAT_CENTRE)
        box.Add(self.listCtrls, 0, wx.ALIGN_CENTRE)
        panel.SetSizerAndFit(box)
    
    def __OnAddClicked(self, event):
        index = self.listCtrls.InsertStringItem(sys.maxint, 'name 1')
        
        panel = wx.Panel(self.listCtrls, -1)
        sizer = wx.BoxSizer(wx.VERTICAL)
        cbb = wx.ComboBox(panel, -1, value = '1', choices = ['1', '2', '3', '4', '5'], style = wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER)
        sizer.Add(cbb, 1, wx.EXPAND)
        panel.SetSizer(sizer)
        
        #cbb =  wx.Button(self.listCtrls, -1, 'Add')
        cbb.Bind(wx.EVT_PAINT, self.__OnPaint)
        self.listCtrls.SetItemWindow(index, 1, panel, expand = True)
        self.listCtrls.Update()
    
    def __OnPaint(self, event):
        event.Skip() 

        
    
    
        
              
        
    
        

解决方法如代码中,SetItemWindow(),添加control到列中的时候,可以先用wx.Panel做位其父控件。这样control不会被一直重绘。我在项目中用到ComboBox时候,遇到了这个情况。其他控件暂时没有遇到过。wxPython 还是有许多问题的。

优质内容筛选与推荐>>
1、java.lang.CharSequence cannot be resolved
2、<转> Mysql group by 详解(写的比较详细)
3、Java学习笔记--反射
4、python 3.x with语句与上下文管理器
5、MySQL数据库中字符集的问题


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号