Change WxPropertyGrid based on button click Topic is solved
Change WxPropertyGrid based on button click
I have a property window that is going to be controlled from the list. Every item on the list corresponds to the same property window but with different colour and label values. The colour is just going to be the background colour of the item. The only question i have is how do i change a property or the colour that has been appended to the wxPropertyGrid based on a new selection.
grid = new wxPropertyGrid(treePanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxPG_AUTO_SORT | wxPG_SPLITTER_AUTO_CENTER| wxPG_DEFAULT_STYLE);
wxPGProperty* prop = grid->Append(new wxColourProperty(wxT("Label Colour"),wxPG_LABEL,wxColour(242, 109, 0)));
grid = new wxPropertyGrid(treePanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxPG_AUTO_SORT | wxPG_SPLITTER_AUTO_CENTER| wxPG_DEFAULT_STYLE);
wxPGProperty* prop = grid->Append(new wxColourProperty(wxT("Label Colour"),wxPG_LABEL,wxColour(242, 109, 0)));
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: Change WxPropertyGrid based on button click
You will need to read this first
In your case you will need to catch relevant event.
To understand which item was clicked you will need to catch event of interest and use the unique names to differentiate items
//add the property in the grid
m_editorGeneralProps->Append(new wxPropertyCategory(_("Label"), "unique-name-here"));
In your case you will need to catch relevant event.
To understand which item was clicked you will need to catch event of interest and use the unique names to differentiate items
//add the property in the grid
m_editorGeneralProps->Append(new wxPropertyCategory(_("Label"), "unique-name-here"));
Code: Select all
void MyClass::OnGridPropChanged(wxPropertyGridEvent &event) // catching wxEVT_PG_SELECTED
{
wxPGProperty *property = event.GetProperty();
wxString name = property->GetName();
wxVariant value = property->GetValue();
if(name == "unique-name-here")
{
//change color here
}
}
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Re: Change WxPropertyGrid based on button click
wxPGProperty* pg = grid->Append(new wxColourProperty(wxT("Label Colour"),wxPG_LABEL,
wxColour(242, 109, 0)));
grid->ChangePropertyValue(pg,new wxColourProperty(wxT("Label Colour"), wxPG_LABEL,
wxColour(*wxBLACK)));
if I just want to change the colour property can I do it using the change property value? I tried this but it's not working
wxColour(242, 109, 0)));
grid->ChangePropertyValue(pg,new wxColourProperty(wxT("Label Colour"), wxPG_LABEL,
wxColour(*wxBLACK)));
if I just want to change the colour property can I do it using the change property value? I tried this but it's not working
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: Change WxPropertyGrid based on button click
Do you want to do that immediately or you do it in some handler? Can you make small example?gillp28 wrote: ↑Tue Jul 09, 2019 2:40 pm wxPGProperty* pg = grid->Append(new wxColourProperty(wxT("Label Colour"),wxPG_LABEL,
wxColour(242, 109, 0)));
grid->ChangePropertyValue(pg,new wxColourProperty(wxT("Label Colour"), wxPG_LABEL,
wxColour(*wxBLACK)));
if I just want to change the colour property can I do it using the change property value? I tried this but it's not working
I have never tested this but if you want to change property you can try this
Code: Select all
void MyClass::OnGridPropChanged(wxPropertyGridEvent &event) // catching wxEVT_PG_SELECTED
{
wxPGProperty *property = event.GetProperty();
wxPGPropArgCls pid(property);
wxColor color = *wxBLACK;
wxVariant value(color);
grid->ChangePropertyValue(pid, value);
}
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Re: Change WxPropertyGrid based on button click
This is the sample I'm working on. So based on the item selected on the listview the property window selected colour changes.
Code: Select all
wxTreeCtrlFrame::wxTreeCtrlFrame(wxWindow* parent, wxWindowID id)
{
Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
SetClientSize(wxSize(500, 500));
wxPanel* treePanel = new wxPanel(this, wxID_ANY);
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* horSize = new wxBoxSizer(wxHORIZONTAL);
listView = new wxListView(treePanel, ID_TREELISTCTRL1, wxDefaultPosition, wxDefaultSize);
wxListItem NewItem;
grid = new wxPropertyGrid(treePanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxPG_AUTO_SORT | wxPG_SPLITTER_AUTO_CENTER| wxPG_DEFAULT_STYLE);
mainSizer->Add(listView, 1, wxEXPAND | wxALL, 4);
mainSizer->Add(grid, 3, wxEXPAND | wxALL, 5);
horSize->Add(addNodeBtn);
horSize->Add(deleteNodeBtn);
horSize->Add(editNodeBtn);
mainSizer->Add(horSize, 0 , wxALIGN_TOP | wxALIGN_RIGHT | wxTOP | wxRIGHT | wxBOTTOM, 4);
treePanel->SetSizer(mainSizer);
listView->AppendColumn("Column 1");
listView->AppendColumn("Column 2");
// Add three items to the list
listView->InsertItem(0, "Item 1");
listView->SetItem(0, 1, "Amber");
listView->SetItemBackgroundColour(0, *wxRED);
listView->InsertItem(1, "Item 2");
listView->SetItem(1, 1, "Blue");
listView->SetItemBackgroundColour(1, *wxRED);
listView->InsertItem(2, "Item 3");
listView->SetItem(2, 1, "Cyan");
listView->SetItemBackgroundColour(2, *wxRED);
pg = grid->Append(new wxColourProperty(wxT("Label Colour"),wxPG_LABEL,
wxColour(242, 109, 0)));
Connect(idMenuQuit, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction)& wxTreeCtrlFrame::OnQuit);
Connect(idMenuAbout, wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction)& wxTreeCtrlFrame::OnAbout);
Connect(ID_TREELISTCTRL1, wxEVT_COMMAND_LIST_ITEM_SELECTED, (wxObjectEventFunction)& wxTreeCtrlFrame::OnNodeSelected);
//*)
}
wxTreeCtrlFrame::~wxTreeCtrlFrame()
{
//(*Destroy(wxTreeCtrlFrame)
//*)
}
void wxTreeCtrlFrame::OnQuit(wxCommandEvent& event)
{
Close();
}
void wxTreeCtrlFrame::OnAbout(wxCommandEvent& event)
{
wxString msg = wxbuildinfo(long_f);
wxMessageBox(msg, _("Welcome to..."));
}
void wxTreeCtrlFrame::OnNodeSelected(wxTreeListEvent& event)
{
wxColour back = listView->GetItemBackgroundColour(listView->GetFocusedItem());
grid->SetPropertyValue(pg, new wxColourProperty(wxT("Label Colour"), wxPG_LABEL,
back));
}
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: Change WxPropertyGrid based on button click
Looking at your code, why do you even use wxPropertyGrid? You have only one property that need to change color.
Have you checked wxColorPickerCtrl?
Have you checked wxColorPickerCtrl?
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Re: Change WxPropertyGrid based on button click
I will be adding more properties after but for now just trying to get the colour part to work.
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: Change WxPropertyGrid based on button click
Appending change it to include unique name
Code: Select all
pg = grid->Append(new wxColourProperty(wxT("Label Colour"),"unique-name-here", wxColour(242, 109, 0)));
Code: Select all
void wxTreeCtrlFrame::OnNodeSelected(wxTreeListEvent& event)
{
wxColour back = listView->GetItemBackgroundColour(listView->GetFocusedItem());
wxPGPropArgCls pid("unique-name-here");
wxVariant value(back);
grid->ChangePropertyValue(pid, value);
}
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: Change WxPropertyGrid based on button click
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?