53、 wxWidgets之自定义wxDataViewProgressRenderer


class MyDataViewProgressRenderer: public wxDataViewProgressRenderer
{
public:

    MyDataViewProgressRenderer( const wxString &label,const wxString &varianttype, wxDataViewCellMode mode, int align )
        : wxDataViewProgressRenderer( label, varianttype, mode, align )
    {
        m_value = 0;
    }
    bool SetValue (long mMinValue,long mMaxValue)
    {
        m_MinVaue = mMinValue;
        m_MaxValue = mMaxValue;
    }
    bool SetValue( const wxVariant &value )
    {
        m_value = (long) value;

        if (m_value < m_MinVaue) m_value = m_MinVaue;
        if (m_value > m_MaxValue) m_value = m_MaxValue;

        return true;
    }

    bool GetValue( wxVariant &value ) const
    {
        value = (long) m_value;
        return true;
    }

#if wxUSE_ACCESSIBILITY
    wxString GetAccessibleDescription() const
    {
        return wxString::Format(wxS("%i %%"), m_value);
    }
#endif // wxUSE_ACCESSIBILITY

    bool Render(wxRect rect, wxDC *dc, int WXUNUSED(state))
    {
        const wxDataViewItemAttr& attr = GetAttr();
        if ( attr.HasColour() )
            dc->SetBackground(attr.GetColour());

        // This is a hack, but native renderers don't support using custom colours,
        // but typically gauge colour is important (e.g. it's commonly green/red to
        // indicate some qualitative difference), so we fall back to the generic
        // implementation which looks ugly but does support using custom colour.
        wxRendererNative& renderer = attr.HasColour()
                                     ? wxRendererNative::GetGeneric()
                                     : wxRendererNative::Get();
        renderer.DrawGauge(
            GetOwner()->GetOwner(),
            *dc,
            rect,
            m_value,
            m_MaxValue);

        return true;
    }

    wxSize GetSize() const
    {
        // Return -1 width because a progress bar fits any width; unlike most
        // renderers, it doesn't have a "good" width for the content. This makes it
        // grow to the whole column, which is pretty much always the desired
        // behaviour. Keep the height fixed so that the progress bar isn't too fat.
        return wxSize(-1, 12);
    }
private :
    long m_value,m_MaxValue=100,m_MinVaue=0;
};
 

 使用方法


    wxDataViewListCtrl* lc = new wxDataViewListCtrl(panelLeftTop,-1 );

    auto *cr = new MyDataViewProgressRenderer("custom","long",wxDATAVIEW_CELL_ACTIVATABLE
                                            , wxDVR_DEFAULT_ALIGNMENT);
    cr->SetValue(0,10);//设置进度条的数值范围
    wxDataViewColumn *columnProgress = new wxDataViewColumn( "customprogress", cr
                                            , 0//关联列的索引,第一个为0。不能错的哦
                                            , wxCOL_WIDTH_DEFAULT
                                            , wxALIGN_LEFT,wxDATAVIEW_COL_RESIZABLE
                                            );

    lc->AppendColumn( columnProgress );

    wxVector<wxVariant> data;
    data.push_back(3);
    lc->AppendItem( data );

    data.clear();//
    data.push_back(7);
    lc->AppendItem( data );

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值