wxSimplebook not showing

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
Mamo_Grag17
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Mar 31, 2022 7:45 pm
Location: Morocco

wxSimplebook not showing

Post by Mamo_Grag17 »

Hello,

There is a frame that hold a sizer, this sizer is the parent of another box sizer, staticLine and wxSimpleBook, the first two children are shown without any problem, but the simple book no, the simple book is defined as a class, not a direct wxSimpleBook object.

This is my code:

Code: Select all

applicationsBox::applicationsBox(int orient) : wxBoxSizer(wxHORIZONTAL)
{

 //some code
 
}

simpleBookBoxSizerClass::simpleBookBoxSizerClass(int orient) : wxBoxSizer(orient)
{
 
 gridSizer = new wxGridSizer(3,3,wxDefaultSize);
 gridSizer->SetMinSize(wxSize(-1,300));

}

simpleBook::simpleBook(wxWindow *parent) : wxSimplebook(parent)
{
 
 wxNotebookPage* page = new wxNotebookPage(this,-1);
 ShowNewPage(page);
 simpleBookBoxSizerObject = new simpleBookBoxSizerClass(wxVERTICAL);
 SetSizerAndFit(simpleBookBoxSizerObject);
 SetMinSize(wxSize(-1,300));

}

frame::frame(const wxString & title) : wxFrame(NULL,wxID_ANY,title,wxDefaultPosition)
{

    //put the panel in the sizer
    mainBoxSizer = new wxBoxSizer(wxVERTICAL);
    SetSizerAndFit(mainBoxSizer);

    //this spacer will hold the two left and right buttons and the searchctrl
    searchAndButtonsSizer = new wxBoxSizer(wxHORIZONTAL);
    mainBoxSizer->Add(searchAndButtonsSizer,0,wxEXPAND);
    searchAndButtonsSizer->SetMinSize(wxSize(-1,50));

    //add a spacer first
    searchAndButtonsSizer->AddStretchSpacer(); 

    //then the left button that will change the wxBookCtrl pages 
    ::wxInitAllImageHandlers();
    wxBitmap leftButtonBitMap("../res/arrow-left.png",wxBITMAP_TYPE_PNG);
    changePanelLeft = new wxBitmapButton(this,changePanelLeftID,leftButtonBitMap,wxPoint(265,7),wxSize(32,32));
    
    leftButtonSizer = new wxBoxSizer(wxVERTICAL);
    leftButtonSizer->AddSpacer(7);
    leftButtonSizer->Add(changePanelLeft,0);
    leftButtonSizer->AddSpacer(7);

    searchAndButtonsSizer->Add(leftButtonSizer,0);
    
    //add another spacer
    searchAndButtonsSizer->AddSpacer(20);

    //then the main searchCtrl
    searchCtrl = new wxSearchCtrl(this,wxID_ANY,"");
    searchCtrl->SetMinSize(wxSize(180,45));
    searchCtrl->SetMaxSize(wxSize(200,45));
    searchCtrl->SetDescriptiveText("search");
    searchCtrl->ShowSearchButton(true);
    searchAndButtonsSizer->Add(searchCtrl,1,wxEXPAND);

    //add a spacer
    searchAndButtonsSizer->AddSpacer(20);

    //this is the right button
    wxBitmap rightButtonBitMap("../res/arrow-right.png",wxBITMAP_TYPE_PNG);
    changePanelRight = new wxBitmapButton(this,changePanelRightID,rightButtonBitMap,wxPoint(510,7),wxSize(32,32));
    
    rightButtonSizer = new wxBoxSizer(wxVERTICAL);
    rightButtonSizer->AddSpacer(7);
    rightButtonSizer->Add(changePanelRight,0);
    rightButtonSizer->AddSpacer(7);
    
    searchAndButtonsSizer->Add(rightButtonSizer,0);
    searchAndButtonsSizer->AddStretchSpacer();

    //a static line for appearence
    staticLine = new wxStaticLine(this,wxID_ANY,wxDefaultPosition,wxSize(-1,3));
    mainBoxSizer->Add(staticLine,0,wxEXPAND);
    
    //now add a spacer
    mainBoxSizer->AddSpacer(5);

    mainSimpleBook = new simpleBook(this);
    mainSimpleBook->Show();
    mainBoxSizer->Add(mainSimpleBook,1,wxEXPAND,wxALL);

}
this is the building error:

Code: Select all

[build] /home/mamograg/Documents/C++ projects/grab/src/gui.cpp: In constructor ‘applicationsBox::applicationsBox(int)’:
[build] /home/mamograg/Documents/C++ projects/grab/src/gui.cpp:25:81: error: no matching function for call to ‘wxStaticBitmap::wxStaticBitmap(applicationsBox*, int, wxBitmap)’
[build]    25 |   applicationImage = new wxStaticBitmap(this,-1,wxBitmap(path,wxBITMAP_TYPE_PNG));
[build]       |                                                                                 ^
[build] In file included from /usr/local/include/wx-3.1/wx/statbmp.h:72,
[build]                  from /home/mamograg/Documents/C++ projects/grab/src/gui.hpp:28,
[build]                  from /home/mamograg/Documents/C++ projects/grab/src/gui.cpp:11:
[build] /usr/local/include/wx-3.1/wx/gtk/statbmp.h:22:5: note: candidate: ‘wxStaticBitmap::wxStaticBitmap(wxWindow*, wxWindowID, const wxBitmapBundle&, const wxPoint&, const wxSize&, long int, const wxString&)’
[build]    22 |     wxStaticBitmap( wxWindow *parent,
[build]       |     ^~~~~~~~~~~~~~
[build] /usr/local/include/wx-3.1/wx/gtk/statbmp.h:22:31: note:   no known conversion for argument 1 from ‘applicationsBox*’ to ‘wxWindow*’
[build]    22 |     wxStaticBitmap( wxWindow *parent,
[build]       |                     ~~~~~~~~~~^~~~~~
[build] /usr/local/include/wx-3.1/wx/gtk/statbmp.h:21:5: note: candidate: ‘wxStaticBitmap::wxStaticBitmap()’
[build]    21 |     wxStaticBitmap();
[build]       |     ^~~~~~~~~~~~~~
[build] /usr/local/include/wx-3.1/wx/gtk/statbmp.h:21:5: note:   candidate expects 0 arguments, 3 provided
[build] [2/3  66% :: 20.179] Building CXX object CMakeFiles/grab.dir/src/application.cpp.o
[build] ninja: build stopped: subcommand failed.
[proc] The command: /usr/bin/cmake --build "/home/mamograg/Documents/C++ projects/grab/build" --config Debug --target all -j 3 -- exited with code: 1 and signal: null
Last edited by Mamo_Grag17 on Sat Sep 24, 2022 6:21 pm, edited 2 times in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxSimplebook not showing

Post by doublemax »

Code: Select all

simpleBookBoxSizerClass::simpleBookBoxSizerClass(int orient) : wxBoxSizer(orient)
{
  gridSizer = new wxGridSizer(3,3,wxDefaultSize);
 gridSizer->SetMinSize(wxSize(-1,300));
}
Is that the whole code of the class? Then it doesn't make any sense.
FWIW: It's very uncommon to subclass wxSizer unless you implement a totally new type of sizer.

Code: Select all

    mainSimpleBook = new simpleBook(this);
    mainSimpleBook->Show();
When the simplebook is empty, how/where do you expect it to show up?
Use the source, Luke!
Mamo_Grag17
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Mar 31, 2022 7:45 pm
Location: Morocco

Re: wxSimplebook not showing

Post by Mamo_Grag17 »

doublemax wrote: Sat Sep 10, 2022 5:01 pm

Code: Select all

simpleBookBoxSizerClass::simpleBookBoxSizerClass(int orient) : wxBoxSizer(orient)
{
  gridSizer = new wxGridSizer(3,3,wxDefaultSize);
 gridSizer->SetMinSize(wxSize(-1,300));
}
Is that the whole code of the class? Then it doesn't make any sense.
Hello,

i made some changes and i still can't even compile the program, please any idea:

Code: Select all

applicationsBox::applicationsBox(int orient) : wxBoxSizer(wxHORIZONTAL)
{
  
  name = getRandomName();
  path = getApplicationImagePath(name);
  
  //show an image
  applicationImage = new wxStaticBitmap(this,-1,wxBitmap(path,wxBITMAP_TYPE_PNG));

  applicationImageBoxSizer = new wxBoxSizer(wxVERTICAL);
  applicationImageBoxSizer->AddSpacer(10);
  applicationImageBoxSizer->Add(applicationImage,0,wxEXPAND,wxALL);
  applicationImageBoxSizer->AddSpacer(10);
  
  nameAndDescriptionBoxSizer = new wxBoxSizer(wxVERTICAL);
  applicationName = new wxStaticText();
  applicationName->SetLabel(name);

  applicationDescription = new wxStaticText();
  applicationDescription->SetLabel(getApplicationDescription(name));
  
  nameAndDescriptionBoxSizer->Add(applicationName);
  nameAndDescriptionBoxSizer->Add(applicationDescription);
 
}

gridSizer::gridSizer(int orient) : wxGridSizer(orient)
{
 makeBoxes();
}

simpleBook::simpleBook(wxWindow *parent) : wxSimplebook(parent)
{
 
 wxNotebookPage* page = new wxNotebookPage(this,-1);
 ShowNewPage(page);
 simpleBookGridSizer = new gridSizer(wxVERTICAL);
 SetSizerAndFit(simpleBookGridSizer);
 SetMinSize(wxSize(-1,300));

}

frame::frame(const wxString & title) : wxFrame(NULL,wxID_ANY,title,wxDefaultPosition)
{

    //put the panel in the sizer
    mainBoxSizer = new wxBoxSizer(wxVERTICAL);
    SetSizerAndFit(mainBoxSizer);

    //initialize the menu bar and menus
    mainBar = new wxMenuBar();
    settings = new wxMenu();
    about = new wxMenu();

    mainBar->Append(settings,"&Settings");
    mainBar->Append(about,"&About");

    SetMenuBar(mainBar);
    
    //this spacer will hold the two left and right buttons and the searchctrl
    searchAndButtonsSizer = new wxBoxSizer(wxHORIZONTAL);
    mainBoxSizer->Add(searchAndButtonsSizer,0,wxEXPAND);
    searchAndButtonsSizer->SetMinSize(wxSize(-1,50));

    //add a spacer first
    searchAndButtonsSizer->AddStretchSpacer(); 

    //then add the left button that will change the wxBookCtrl pages 
    ::wxInitAllImageHandlers();
    wxBitmap leftButtonBitMap("../res/arrow-left.png",wxBITMAP_TYPE_PNG);
    changePanelLeft = new wxBitmapButton(this,changePanelLeftID,leftButtonBitMap,wxPoint(265,7),wxSize(32,32));
    
    leftButtonSizer = new wxBoxSizer(wxVERTICAL);
    leftButtonSizer->AddSpacer(7);
    leftButtonSizer->Add(changePanelLeft,0);
    leftButtonSizer->AddSpacer(7);

    searchAndButtonsSizer->Add(leftButtonSizer,0);
    
    //add another spacer
    searchAndButtonsSizer->AddSpacer(20);

    //then the main searchCtrl
    searchCtrl = new wxSearchCtrl(this,wxID_ANY,"");
    searchCtrl->SetMinSize(wxSize(180,45));
    searchCtrl->SetMaxSize(wxSize(200,45));
    searchCtrl->SetDescriptiveText("search");
    searchCtrl->ShowSearchButton(true);
    searchAndButtonsSizer->Add(searchCtrl,1,wxEXPAND);

    //add a spacer
    searchAndButtonsSizer->AddSpacer(20);

    //this is the right button
    wxBitmap rightButtonBitMap("../res/arrow-right.png",wxBITMAP_TYPE_PNG);
    changePanelRight = new wxBitmapButton(this,changePanelRightID,rightButtonBitMap,wxPoint(510,7),wxSize(32,32));
    
    rightButtonSizer = new wxBoxSizer(wxVERTICAL);
    rightButtonSizer->AddSpacer(7);
    rightButtonSizer->Add(changePanelRight,0);
    rightButtonSizer->AddSpacer(7);
    
    searchAndButtonsSizer->Add(rightButtonSizer,0);
    searchAndButtonsSizer->AddStretchSpacer();

    //a static line for appearence
    staticLine = new wxStaticLine(this,wxID_ANY,wxDefaultPosition,wxSize(-1,3));
    mainBoxSizer->Add(staticLine,0,wxEXPAND);
    
    //now add a spacer
    mainBoxSizer->AddSpacer(5);

    //this will show the applications
    mainSimpleBook = new simpleBook(this);
    mainSimpleBook->Show();
    mainBoxSizer->Add(mainSimpleBook,1,wxEXPAND,wxALL);

}

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxSimplebook not showing

Post by ONEEYEMAN »

Hi,
What errors do you get?
What compiler and how do you building?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxSimplebook not showing

Post by doublemax »

Code: Select all

applicationsBox::applicationsBox(int orient) : wxBoxSizer(wxHORIZONTAL)
You're trying too many things at once. Like i already said, subclassing wxSizer is very unsual, and for your purpose it's the wrong thing to do.

If you want to group controls together, subclass wxPanel.
Use the source, Luke!
Mamo_Grag17
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Mar 31, 2022 7:45 pm
Location: Morocco

Re: wxSimplebook not showing

Post by Mamo_Grag17 »

Thank you for responding,

So here is what I have understood:

The sizers can't be subclassed, and for that i need to just declare the first sizer and put it in the simple book, then i will add the applications boxes to the sizer, after that i will add the panels to the applications boxes?

Am i right?

Thank you.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxSimplebook not showing

Post by ONEEYEMAN »

Hi,
Sizers can be subclasses, but the scenario where it's needed is 0.00000001 % of all possible ones.

Can you draw the layout you are after and post a picture?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxSimplebook not showing

Post by doublemax »

Mamo_Grag17 wrote: Sat Sep 24, 2022 7:55 pm The sizers can't be subclassed, and for that i need to just declare the first sizer and put it in the simple book, then i will add the applications boxes to the sizer, after that i will add the panels to the applications boxes?
Not exactly. Usually the pages you add to the wxSimpleBook will be wxPanels. Each wxPanel will have one toplevel sizer into which you put the controls (and maybe other sizers depending on your layout).
Use the source, Luke!
Post Reply