I would like to make Bitmap Toggle Buttons work like radio buttons. Though the extent of my ability to extend a control is to override the constructor. I'm a bit lost how to do this.
My first thought is to store the previously pressed toggle button somewhere then on the new click turn the old button off change the pointer and make sure the pressed button is toggled on. Though I don't know how I would work grouping into this.
Any help is much appreciated.
Grouped toggle buttons Topic is solved
This is what I would do :
1) create a wxBitmapRadioGroup class that derives from wxPanel.
2) give this class a method to add an option. this method creates a bitmap button and adds it to the panel; it can also store a pointer to it in a vector to make it easier to access later
3) connect these buttons so you get their events
4) when you receive the event that one is pressed, iterate through your vector and "uncheck" all others
1) create a wxBitmapRadioGroup class that derives from wxPanel.
2) give this class a method to add an option. this method creates a bitmap button and adds it to the panel; it can also store a pointer to it in a vector to make it easier to access later
3) connect these buttons so you get their events
4) when you receive the event that one is pressed, iterate through your vector and "uncheck" all others
"Keyboard not detected. Press F1 to continue"
-- Windows
-- Windows
-
- Earned a small fee
- Posts: 12
- Joined: Wed Mar 17, 2010 9:17 am
Thanks for the help Auria.
I quickly was trying to test it. Though i must not be using Connect correctly.
I have the code below
And i get the following error.
I also tried EVT_TOGGLEBUTTON and same result. Google hasn't given me much help either.
EDIT:
The toggle button code provided me with wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
Which seems to work
I quickly was trying to test it. Though i must not be using Connect correctly.
I have the code below
Code: Select all
Connect(b1->GetId(),wxEVT_TOGGLEBUTTON,
wxCommandEventHandler(ToolsPanel::clearTools));
Code: Select all
error: `wxEVT_TOGGLEBUTTON' was not declared in this scope|
EDIT:
The toggle button code provided me with wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
Which seems to work
Last edited by greeniekin on Wed Apr 14, 2010 1:51 am, edited 1 time in total.
-
- Earned a small fee
- Posts: 12
- Joined: Wed Mar 17, 2010 9:17 am
Thank you a lot Auria.
Here is what I did if it interests anyone else.
[/code]
Here is what I did if it interests anyone else.
Code: Select all
class ToolsPanel: public wxPanel
{
public:
ToolsPanel(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = "panel");
private:
wxBitmapToggleButton* selectedTool;
void changeTool(wxCommandEvent& event);
};
ToolsPanel::ToolsPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name):
wxPanel(parent, id, pos, size)
{
wxWrapSizer *flex = new wxWrapSizer();
wxBitmap tb_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE,wxART_OTHER,wxSize(16,16));
selectedTool = new wxBitmapToggleButton(this,wxID_ANY,tb_bmp);
flex->Add(selectedTool,1,wxALL|wxALIGN_RIGHT);
Connect(selectedTool->GetId(),wxEVT_COMMAND_TOGGLEBUTTON_CLICKED ,
wxCommandEventHandler(ToolsPanel::changeTool));
selectedTool = new wxBitmapToggleButton(this,wxID_ANY,tb_bmp);
flex->Add(selectedTool,1,wxALL|wxALIGN_RIGHT);
Connect(selectedTool->GetId(),wxEVT_COMMAND_TOGGLEBUTTON_CLICKED ,
wxCommandEventHandler(ToolsPanel::changeTool));
selectedTool = new wxBitmapToggleButton(this,wxID_ANY,tb_bmp);
flex->Add(selectedTool,1,wxALL|wxALIGN_RIGHT);
Connect(selectedTool->GetId(),wxEVT_COMMAND_TOGGLEBUTTON_CLICKED ,
wxCommandEventHandler(ToolsPanel::changeTool));
selectedTool->SetValue(true);
this->SetSizer(flex);
}
void ToolsPanel::changeTool(wxCommandEvent &event)
{
selectedTool->SetValue(false);
selectedTool=(wxBitmapToggleButton*)event.GetEventObject();
selectedTool->SetValue(true);
}