Reputation: 1
I am using a wxNotebook to represent two tabs in my app. And in the 1st tab i have a wxScrolledWindow which receives data from the worker thread and displays it. The problem is that when the data is received from the worker thread and displayed onto the 1st tab(in terms of wxButtons), the buttons are not scrollable. But when I switch to the 2nd tab and then again come(switch) back to tab1 the buttons become scrollable. I have attached a screenshot of the situation I have. The buttons shown are not scrollable initially when they are created/displayed inside tab1. But when I go to tab2 and then back to tab1 they become scrollable. This is the code that i use to send data:
wxThread::ExitCode WorkerThread::Entry()
{
wxThreadEvent *sendEvent = new wxThreadEvent(wxEVT_THREAD, ID_WORKER_THREAD);
for(int i = 0; i< 100; i++)
{
sendEvent->SetInt(i);
std::cout<<"Sending event"<<std::endl;
wxQueueEvent(m_parentScrolled, sendEvent->Clone());
}
delete sendEvent;
return NULL;
}
And this is how i receive the data and display the buttons:
void MyScrolledWindow::onWorkerThread(wxThreadEvent &event)
{
std::cout<<"Student event received"<<std::endl;
wxButton* b = new wxButton(this, wxID_ANY, wxString::Format(wxT("Button %i"), event.GetInt()));
myScrolledWindow_Sizer->Add(b, 0, wxEXPAND, 3);
Layout();
}
How can I make the buttons scrollable at the time when they are created so that I don't have to switch back and forth between tab1 and tab2 to make them scrollable. Also the WorkerThread was created from a class MyNotebook onClick event handler. The code that i used to create the thread is like this:
void MyNotebook::onClick(wxMouseEvent &event)
{
MyScrolledWindow *myScrolledWindow = dynamic_cast<MyScrolledWindow*>(FindWindowById(15));
//do the check if the above pointer is valid or not then proceed for the creation of thread
//create the thread
WorkerThread *workerThread = new WorkerThread(this, myScrolledWindow);
........//other code here
}
Can this be the problem? When i return NULL from inside the WorkerThread::Entry
, the control flow comes here. Can this be the cause of the problem?
Upvotes: 0
Views: 46
Reputation: 3554
In MyScrolledWindow::onWorkerThread
, in addition to calling Layout you need need to call FitInside to recompute the virtual size of the window. Add the line FitInside();
to the end of the method.
Upvotes: 1