wxListBook issues with ImageList and SetPageImage

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
kshitij_ds
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Wed Jun 25, 2008 3:37 pm

wxListBook issues with ImageList and SetPageImage

Post by kshitij_ds »

Hi,
In my application i am doing this:

1) Creating a wxListBook
2) Calling AddPage on wxListBook to add few pages
3) Create a wxImageList with size 32x32
4) Call SetImageList of wxListBook
5) Assign image to each note book page using SetPageImage(...)

I even stepped through my and wxWidgets code to verify that images are getting assigned and that SetPageImage(...) and SetImageList return TRUE.

However, i am not able to see any images assigned to my pages.

Here is sample code:

Code: Select all

m_cNoteBook = new wxListbook( itemueDialog1, ID_NOTEBOOK, wxDefaultPosition, wxDefaultSize, wxBK_TOP );
 m_cNoteBook->AddPage(itemPanel1, _("First Page"));
 m_cNoteBook->AddPage(itemPanel2, _("Second Page")); 
 m_cNoteBook->AddPage(itemPanel3, _("Third Page"));

  prefImageList_.Create(32, 32);
  for(int i=0;i<3;i++)
  {
    prefImageList_.Add(wxBitmap(...)); //Here i add images to the imagelist
  }
  m_cNoteBook->SetImageList(&prefImageList_);
  
  for(int i=0;i<3;i++)
  {
    m_cNoteBook->SetPageImage(i,i);
  }
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

Hi,
is the prefImageList_ local variable? wxListBook doesn't save own copy of the wxImageList, it just save the pointer.
Try this:

Code: Select all

wxImageList* prefImageList_;
...
  prefImageList_ = new wxImageList(32, 32);
  for(int i=0;i<3;i++)
  {
    prefImageList_->Add(wxBitmap(...)); //Here i add images to the imagelist
  }
  m_cNoteBook->AssignImageList(prefImageList_);
...
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
kshitij_ds
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Wed Jun 25, 2008 3:37 pm

Post by kshitij_ds »

no, its a private variable in my wxDialog class.
Don't worry i figured it out... :)
The issue here was that the wxImageList was required to be created before the wxListBook was created and then assign the image list to the list book ctrl.
I was basically creating the image list after creating the notebook control and later assigning page images.
Though IMO that should have worked as well, but unfortunately it does not :(. I did debug into wxWidgets code and saw that the images were being assinged.


Anyways, my other question was that when you click on an icon in wxListBook only the bottom text is selected. I would like to select the icon as well. The functionality is similar to the Preferences dialog in Xcode.
Post Reply