Reputation: 153
As the title, is possible to change the background color of a single cell in a wxDataViewListCtrl? If not, is possible to change the background color of an entire row? How can I do it? Others solutions? Thanks a lot in advance for some advice
Upvotes: 2
Views: 624
Reputation: 153
For those who might be interested I have solved as follows
class MyColorRenderer: public wxDataViewCustomRenderer { public: explicit MyColorRenderer(wxDataViewCellMode mode) : wxDataViewCustomRenderer("string", mode, wxALIGN_CENTER) { } virtual bool Render( wxRect rect, wxDC *dc, int state ) override; virtual bool ActivateCell(const wxRect& WXUNUSED(cell), wxDataViewModel*WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col), const wxMouseEvent *mouseEvent) override { return false; } virtual wxSize GetSize() const override { return wxSize(60,20); } virtual bool SetValue( const wxVariant &value ) override { m_value = value.GetString(); return true; } virtual bool GetValue( wxVariant &WXUNUSED(value) ) const override { return true; } virtual bool HasEditorCtrl() const override { return true; } virtual wxWindow* CreateEditorCtrl(wxWindow* parent, wxRect labelRect, const wxVariant& value) override { wxTextCtrl* text = new wxTextCtrl(parent, wxID_ANY, value, labelRect.GetPosition(), labelRect.GetSize(), wxTE_PROCESS_ENTER); text->SetInsertionPointEnd(); return text; } virtual bool GetValueFromEditorCtrl(wxWindow* ctrl, wxVariant& value) override { wxTextCtrl* text = wxDynamicCast(ctrl, wxTextCtrl); if ( !text ) return false; value = text->GetValue(); return true; } private: wxString m_value; };
bool MyColorRenderer::Render( wxRect rect, wxDC *dc, int state ) { dc->SetBrush( wxColour(m_value) ); rect.Deflate(2); dc->DrawRoundedRectangle( rect, 5 ); return true; }
lst->AppendColumn(new wxDataViewColumn("Colore",new MyColorRenderer(wxDATAVIEW_CELL_INERT),5, 60, wxALIGN_CENTER));
Upvotes: 2
Reputation: 22688
You can override wxDataViewListModel::GetAttrByRow()
in your custom model to return the attributes with the colours (and fonts etc) you want for any cell.
Upvotes: 1