wxPopupWindow Do Not Receive focsu or its any child Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

wxPopupWindow Do Not Receive focsu or its any child

Post by Harsh »

Code: Select all

#include<wx/wx.h>
#include<wx/popupwin.h>
#include<wx/statline.h>

class MyFrame : public wxFrame{
	    wxPanel *panel,*p;
        wxBoxSizer *vbox,*hbox;
		wxStaticText *st;
        wxButton *btn;
		wxTextCtrl *txt1;
        int i=0;
		
public : 
	MyFrame():wxFrame(NULL,wxID_ANY,"Child Focus"){
		SetSize(800,550);

		wxPopupWindow *pop=new wxPopupWindow(this);
		pop->SetSize(650,250);
		
		vbox=new wxBoxSizer(wxVERTICAL);
    
		hbox=new wxBoxSizer(wxHORIZONTAL);
		p=new wxPanel(pop,wxID_ANY,wxDefaultPosition,wxSize(-1,30));
		p->SetFont(wxFont(14,wxFONTFAMILY_DEFAULT,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,"Georgia"));
		p->SetForegroundColour(wxColour("#000000"));
		p->SetBackgroundColour(wxColour("#FBC403"));
		hbox->Add(new wxStaticText(p,wxID_ANY,wxT("Product Information : ")),0,wxEXPAND|wxLEFT|wxTOP,5);
		p->SetSizer(hbox);
		vbox->Add(p,0,wxEXPAND);
		
		vbox->AddSpacer(5);

		hbox=new wxBoxSizer(wxHORIZONTAL);
		st=new wxStaticText(pop,wxID_ANY,wxT("Product Name : "),wxDefaultPosition,wxSize(132,30));
		hbox->Add(st);
		txt1=new wxTextCtrl(pop,wxID_ANY,wxT("1234567890"),wxDefaultPosition,wxSize(200,30));
		txt1->SetBackgroundColour(wxColour("#000000"));
		txt1->SetForegroundColour(wxColour("#FBC403"));
		hbox->Add(txt1);

		hbox->AddStretchSpacer();

		st=new wxStaticText(pop,wxID_ANY,wxT("Pack : "));
		hbox->Add(st);
		txt1=new wxTextCtrl(pop,wxID_ANY,wxT("10"),wxDefaultPosition,wxSize(200,30));
		txt1->SetBackgroundColour(wxColour("#000000"));
		txt1->SetForegroundColour(wxColour("#FBC403"));
		txt1->SetFocus();
		hbox->Add(txt1);
		vbox->Add(hbox,0,wxEXPAND|wxALL,5);

		vbox->AddSpacer(5);

		hbox=new wxBoxSizer(wxHORIZONTAL);
		st=new wxStaticText(pop,wxID_ANY,wxT("Company : "),wxDefaultPosition,wxSize(132,30));
		hbox->Add(st);
		txt1=new wxTextCtrl(pop,wxID_ANY,wxT("ABC Company"),wxDefaultPosition,wxSize(200,30));
		txt1->SetBackgroundColour(wxColour("#000000"));
		txt1->SetForegroundColour(wxColour("#FBC403"));
		hbox->Add(txt1);

		hbox->AddStretchSpacer();

		st=new wxStaticText(pop,wxID_ANY,wxT("Category : "));
		hbox->Add(st);
		txt1=new wxTextCtrl(pop,wxID_ANY,wxT("General"),wxDefaultPosition,wxSize(200,30));
		txt1->SetBackgroundColour(wxColour("#000000"));
		txt1->SetForegroundColour(wxColour("#FBC403"));
		hbox->Add(txt1);
		vbox->Add(hbox,0,wxEXPAND|wxALL,5);

		vbox->AddSpacer(5);

		hbox=new wxBoxSizer(wxHORIZONTAL);
		st=new wxStaticText(pop,wxID_ANY,wxT("GST : "),wxDefaultPosition,wxSize(132,30));
		hbox->Add(st);
		txt1=new wxTextCtrl(pop,wxID_ANY,wxT("18%"),wxDefaultPosition,wxSize(200,30));
		txt1->SetBackgroundColour(wxColour("#000000"));
		txt1->SetForegroundColour(wxColour("#FBC403"));
		hbox->Add(txt1);

		hbox->AddStretchSpacer();

		st=new wxStaticText(pop,wxID_ANY,wxT("Hazardous : "));
		hbox->Add(st);
		txt1=new wxTextCtrl(pop,wxID_ANY,wxT("No"),wxDefaultPosition,wxSize(200,30));
		txt1->SetBackgroundColour(wxColour("#000000"));
		txt1->SetForegroundColour(wxColour("#FBC403"));
		hbox->Add(txt1);
		vbox->Add(hbox,0,wxEXPAND|wxALL,5);
		vbox->AddSpacer(5);

		vbox->Add(new wxStaticLine(pop),0,wxEXPAND);
		
		pop->SetSizer(vbox);
		pop->Center();
		pop->Show(true);
		pop->Layout();
		this->Layout();

		pop->SetFocus();
		txt1->SetFocus();
	}
};

class MyApp: public wxApp
{
    wxFrame* m_frame;
public:
    
    bool OnInit()
    {
        m_frame = new MyFrame();
        m_frame->Show();
        return true;
    } 
    
};

IMPLEMENT_APP(MyApp);
At end if program I have called pop->SetFocus() and txt1->SetFocus(); But it does not work.
Any of the wxTextCtrl do not get focus even after mouse click.
Is There any solution to set focus on creation of wxPopupWindow ?
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

Re: wxPopupWindow Do Not Receive focsu or its any child

Post by Harsh »

Tried wxPopupTransientWindow It also has the same issue.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxPopupWindow Do Not Receive focsu or its any child

Post by doublemax »

It makes no sense to create a wxPopupWindow in a constructor of a frame. They are usually created when you need them. What are you trying to do?
Use the source, Luke!
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

Re: wxPopupWindow Do Not Receive focsu or its any child

Post by Harsh »

doublemax wrote: Sat May 29, 2021 2:30 pm It makes no sense to create a wxPopupWindow in a constructor of a frame. They are usually created when you need them. What are you trying to do?
Thank You! @DOUBLEMAX :D :D :D :D

Created wxPopupWindow in event functor and it worked greate.
Post Reply