Button is focused when I run application Topic is solved
Button is focused when I run application
When I run the application I made, first button is focused (blue line going around it).
Picture of it: http://i68.tinypic.com/6xsnro.png
I don't want it to be focused at start. How can I fix it?
-ValeV
Picture of it: http://i68.tinypic.com/6xsnro.png
I don't want it to be focused at start. How can I fix it?
-ValeV
Re: Button is focused when I run application
Hi,
Can you show some code?
Did you create this button as the first control?
Thank you.
Can you show some code?
Did you create this button as the first control?
Thank you.
-
- Super wx Problem Solver
- Posts: 469
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: Button is focused when I run application
The only thing I can think of that
- should work on all platforms
- won't break the tab order
Code: Select all
wxPanel* panel = new wxPanel(this);
panel->Hide();
wxButton* button1 = new wxButton(panel, wxID_ANY, "Button1");
wxButton* button2 = new wxButton(panel, wxID_ANY, "Button2");
wxButton* button3 = new wxButton(panel, wxID_ANY, "Button3");
wxButton* button4 = new wxButton(panel, wxID_ANY, "Button4");
wxButton* button5 = new wxButton(panel, wxID_ANY);
button5->Hide();
wxGridSizer* sizer = new wxGridSizer(2);
sizer->Add(button1);
sizer->Add(button2);
sizer->Add(button3);
sizer->Add(button4);
panel->SetSizer(sizer);
panel->Layout();
button5->SetFocus();
panel->Show();
Re: Button is focused when I run application
Thanks! I addedNew Pagodi wrote: ↑Thu Jun 06, 2019 3:11 pm The only thing I can think of thatis to add an extra hidden item and initially set the focus to it. For example, a frame with 4 buttons constructor might look like this:
- should work on all platforms
- won't break the tab order
Code: Select all
wxPanel* panel = new wxPanel(this); panel->Hide(); wxButton* button1 = new wxButton(panel, wxID_ANY, "Button1"); wxButton* button2 = new wxButton(panel, wxID_ANY, "Button2"); wxButton* button3 = new wxButton(panel, wxID_ANY, "Button3"); wxButton* button4 = new wxButton(panel, wxID_ANY, "Button4"); wxButton* button5 = new wxButton(panel, wxID_ANY); button5->Hide(); wxGridSizer* sizer = new wxGridSizer(2); sizer->Add(button1); sizer->Add(button2); sizer->Add(button3); sizer->Add(button4); panel->SetSizer(sizer); panel->Layout(); button5->SetFocus(); panel->Show();
Code: Select all
wxButton* button5 = new wxButton(Panel1, wxID_ANY);
button5->SetFocus();
button5->Hide();
Thank you!
I can show you code, dont know which part though, the drawing part?
Code: Select all
BinaryConverterFrame::BinaryConverterFrame(wxWindow* parent,wxWindowID id)
{
//(*Initialize(BinaryConverterFrame)
wxBoxSizer* BoxSizer1;
wxBoxSizer* BoxSizer2;
wxBoxSizer* BoxSizer3;
wxFlexGridSizer* FlexGridSizer1;
wxMenu* Menu1;
wxMenu* Menu2;
wxMenuBar* MenuBar1;
wxMenuItem* MenuItem1;
wxMenuItem* MenuItem2;
wxStaticBoxSizer* StaticBoxSizer1;
wxStaticBoxSizer* StaticBoxSizer2;
Create(parent, wxID_ANY, _("BinaryConverter"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
FlexGridSizer1 = new wxFlexGridSizer(2, 1, 0, 0);
FlexGridSizer1->AddGrowableCol(0);
FlexGridSizer1->AddGrowableRow(0);
FlexGridSizer1->AddGrowableRow(1);
StaticBoxSizer1 = new wxStaticBoxSizer(wxHORIZONTAL, Panel1, _("EDS to binary converter"));
BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
Button1 = new wxButton(Panel1, ID_BUTTON1, _("Browse controller\'s EDS file"), wxDefaultPosition, wxSize(148,38), 0, wxDefaultValidator, _T("ID_BUTTON1"));
BoxSizer2->Add(Button1, 1, wxALL|wxEXPAND, 5);
Button2 = new wxButton(Panel1, ID_BUTTON2, _("Save"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
BoxSizer2->Add(Button2, 1, wxALL|wxEXPAND, 5);
StaticBoxSizer1->Add(BoxSizer2, 1, wxALL|wxEXPAND, 5);
FlexGridSizer1->Add(StaticBoxSizer1, 1, wxALL|wxEXPAND, 5);
StaticBoxSizer2 = new wxStaticBoxSizer(wxHORIZONTAL, Panel1, _("Binary to text converter"));
BoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
Button3 = new wxButton(Panel1, ID_BUTTON3, _("Choose binary file with\ncontroller NV-RAM data"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
BoxSizer3->Add(Button3, 1, wxALL|wxEXPAND, 5);
Button4 = new wxButton(Panel1, ID_BUTTON4, _("Save"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
BoxSizer3->Add(Button4, 1, wxALL|wxEXPAND, 5);
wxButton* button5 = new wxButton(Panel1, wxID_ANY);
button5->SetFocus();
button5->Hide();
StaticBoxSizer2->Add(BoxSizer3, 1, wxALL|wxEXPAND, 5);
FlexGridSizer1->Add(StaticBoxSizer2, 1, wxALL|wxEXPAND, 5);
Panel1->SetSizer(FlexGridSizer1);
FlexGridSizer1->Fit(Panel1);
FlexGridSizer1->SetSizeHints(Panel1);
BoxSizer1->Add(Panel1, 1, wxEXPAND, 5);
SetSizer(BoxSizer1);
MenuBar1 = new wxMenuBar();
Menu1 = new wxMenu();
MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
Menu1->Append(MenuItem1);
MenuBar1->Append(Menu1, _("&File"));
Menu2 = new wxMenu();
MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
Menu2->Append(MenuItem2);
MenuBar1->Append(Menu2, _("Help"));
SetMenuBar(MenuBar1);
StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
int __wxStatusBarWidths_1[1] = { -1 };
int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
SetStatusBar(StatusBar1);
FileDialog1 = new wxFileDialog(this, _("Select file"), wxEmptyString, wxEmptyString, _("EDS files (*.eds)|*.eds"), wxFD_OPEN|wxFD_FILE_MUST_EXIST, wxDefaultPosition, wxDefaultSize, _T("wxFileDialog"));
FileDialog2 = new wxFileDialog(this, _("Select file"), wxEmptyString, wxEmptyString, _("BIN files (*.bin)|*.bin"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT, wxDefaultPosition, wxDefaultSize, _T("wxFileDialog"));
FileDialog3 = new wxFileDialog(this, _("Select file"), wxEmptyString, wxEmptyString, _("BIN files (*.bin)|*.bin"), wxFD_DEFAULT_STYLE|wxFD_OPEN|wxFD_FILE_MUST_EXIST, wxDefaultPosition, wxDefaultSize, _T("wxFileDialog"));
FileDialog4 = new wxFileDialog(this, _("Select file"), wxEmptyString, wxEmptyString, _("TXT files (*.txt)|*.txt"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT, wxDefaultPosition, wxDefaultSize, _T("wxFileDialog"));
BoxSizer1->Fit(this);
BoxSizer1->SetSizeHints(this);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&BinaryConverterFrame::OnButton1Click);
Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&BinaryConverterFrame::OnButton2Click);
Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&BinaryConverterFrame::OnButton3Click);
Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&BinaryConverterFrame::OnButton4Click);
Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&BinaryConverterFrame::OnQuit);
Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&BinaryConverterFrame::OnAbout);
//*)
}
Sorry, I don't know what that means. I use wxSmith to build GUI.
Re: Button is focused when I run application
I noticed additional bug/feature I don't like, in all my applications. When I click on any button in any of my apps, the focus stays on this button even after the button did his thing (the blue square around the button is still visible, like in my first picture in this forum thread). Surely there is an already known solution for this and not some quick half fix?
Re: Button is focused when I run application
That's the default behavior under Windows. You should see this in all applications (not only wxWidgets ones).When I click on any button in any of my apps, the focus stays on this button even after the button did his thing (the blue square around the button is still visible, like in my first picture in this forum thread).
Use the source, Luke!
Re: Button is focused when I run application
Ah yes, it's just that in my app it's more annoying because of the blue border. (in other applications there is not)doublemax wrote: ↑Fri Jun 07, 2019 7:44 amThat's the default behavior under Windows. You should see this in all applications (not only wxWidgets ones).When I click on any button in any of my apps, the focus stays on this button even after the button did his thing (the blue square around the button is still visible, like in my first picture in this forum thread).
But what about first button being focused on application start (my original question)?
Re: Button is focused when I run application
Isn't this also the usual default button vs focused item question?
See e.g. here viewtopic.php?t=45174
See e.g. here viewtopic.php?t=45174
Re: Button is focused when I run application
Try setting the focus to the frame.But what about first button being focused on application start (my original question)?
Code: Select all
this->SetFocus();
Use the source, Luke!
Re: Button is focused when I run application
I see, I put focus on highest label, though your code works better. Thank you.doublemax wrote: ↑Fri Jun 07, 2019 10:48 amTry setting the focus to the frame.But what about first button being focused on application start (my original question)?Code: Select all
this->SetFocus();