AddTool to specific position at toolbar

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
zhouhao
Earned some good credits
Earned some good credits
Posts: 144
Joined: Tue Dec 06, 2005 7:02 am

AddTool to specific position at toolbar

Post by zhouhao » Tue Apr 03, 2007 5:15 pm

I'm testing toolbar functions in following code:

Code: Select all


#ifdef __WXMSW__
  int width = 24;
#else
  int width = 16;
#endif
  int currentX = 5;

  toolBar->AddTool(wxID_NEW, *(toolBarBitmaps[0]), wxNullBitmap, false, currentX, -1, (wxObject *) NULL, "New file");
  currentX += width + 5;
  toolBar->AddTool(wxID_OPEN, *(toolBarBitmaps[1]), wxNullBitmap, false, currentX, -1, (wxObject *) NULL, "Open file");
  currentX += width + 5;
  toolBar->AddTool(wxID_SAVE, *(toolBarBitmaps[2]), wxNullBitmap, false, currentX, -1, (wxObject *) NULL, "Save file");
  currentX += width + 5;
  toolBar->AddSeparator();
  toolBar->AddTool(wxID_COPY, *(toolBarBitmaps[3]), wxNullBitmap, false, currentX, -1, (wxObject *) NULL, "Copy");
  currentX += width + 5;
  toolBar->AddTool(wxID_CUT, *(toolBarBitmaps[4]), wxNullBitmap, false, currentX, -1, (wxObject *) NULL, "Cut");
  currentX += width + 5;
  toolBar->AddTool(wxID_PASTE, *(toolBarBitmaps[5]), wxNullBitmap, false, currentX, -1, (wxObject *) NULL, "Paste");
  currentX += width + 5;
  toolBar->AddSeparator();
  toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, false, currentX, -1, (wxObject *) NULL, "Print");
  currentX += width + 50;
  toolBar->AddSeparator();
  toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, false, currentX, -1, (wxObject *) NULL, "Help");

  toolBar->Realize();

Please note the last currentX. I purposely add 50 instead of 5 to it. But it won't change the result. There is no extra space added between the last 2 tool. I'm wondering why this doesn't work. Or in another word, can I add tool into specific position instead of auto-aligning?

zhouhao
Earned some good credits
Earned some good credits
Posts: 144
Joined: Tue Dec 06, 2005 7:02 am

Post by zhouhao » Tue Apr 03, 2007 6:21 pm

By the way, the AddSeperator doesn't work either unless use wxFrame::CreateToolbar. I guess there are some bugs here. I'm using wxWidgets 2.8.3.

Saurabh
Earned some good credits
Earned some good credits
Posts: 117
Joined: Thu Sep 07, 2006 10:25 am
Location: India
Contact:

Post by Saurabh » Wed Apr 04, 2007 5:55 am

yes I too have experienced it. The only solution I found was using a panel as a toolbar in my project. I hope you can do that too. Then ur free to do whatever you want to

zhouhao
Earned some good credits
Earned some good credits
Posts: 144
Joined: Tue Dec 06, 2005 7:02 am

Post by zhouhao » Fri Apr 06, 2007 2:03 pm

Saurabh wrote:yes I too have experienced it. The only solution I found was using a panel as a toolbar in my project. I hope you can do that too. Then ur free to do whatever you want to
Thanks for your reply.But I need full function toolbar. If I use panel I have to write a lot of code to simulate the toolbar. My temporary solution is add wxStaticLine with height = 0 to control the position of my tools.

Post Reply