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 );