Statusbar Beginner

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
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Statusbar Beginner

Post by Nick »

I tried 2 ways to change the style of the Statusbar but none of them work!
I'm trying to follow what I read in the wxFrame and wxStatusbar Class but something is missing
I wish the first form works because it has less code written

Attempt 1

Code: Select all

      CreateStatusBar(3, wxSB_SUNKEN); // Does not display correctly
      SetStatusText("Field 1", 0);
      SetStatusText("Field 2", 1);
      SetStatusText("Field 3", 2);
Attempt 2

Code: Select all

      wxStatusBar *StatusBar = new wxStatusBar(this);
      StatusBar->SetFieldsCount(3);
      StatusBar->SetStatusText("Field 1",0);
      StatusBar->SetStatusText("Field 2",1);
      StatusBar->SetStatusText("Field 3",2);
      StatusBar->SetStatusStyles(0, wxSB_SUNKEN); // No Work
      SetStatusBar(StatusBar);
My complete example

Code: Select all

#include <wx/app.h>
#include <wx/frame.h>

class FrmMain: public wxFrame {
public:
   FrmMain(): wxFrame(NULL, wxID_ANY, "") {
      CreateStatusBar(3, wxSB_SUNKEN); // Does not display correctly
      SetStatusText("Field 1", 0);
      SetStatusText("Field 2", 1);
      SetStatusText("Field 3", 2);
      
      // wxStatusBar *StatusBar = new wxStatusBar(this);
      // StatusBar->SetFieldsCount(3);
      // StatusBar->SetStatusText("Field 1",0);
      // StatusBar->SetStatusText("Field 2",1);
      // StatusBar->SetStatusText("Field 3",2);
      // StatusBar->SetStatusStyles(0, wxSB_SUNKEN); // No Work
      // SetStatusBar(StatusBar);
   }
};

class MyProgram: public wxApp {
   bool OnInit() {
      (new FrmMain)->Show();
      return true;
   }
};

wxIMPLEMENT_APP(MyProgram);
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Statusbar Beginner

Post by doublemax »

The style flag is a bit mask. Try this:

Code: Select all

CreateStatusBar(3, wxSTB_DEFAULT_STYLE | wxSB_SUNKEN); 
But depending on the OS/theme it's also possible that the visual style is ignored and the status bar always looks the same.
Use the source, Luke!
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Statusbar Beginner

Post by Nick »

doublemax wrote: Fri Nov 29, 2019 11:13 am The style flag is a bit mask. Try this:

Code: Select all

CreateStatusBar(3, wxSTB_DEFAULT_STYLE | wxSB_SUNKEN); 
But depending on the OS/theme it's also possible that the visual style is ignored and the status bar always looks the same.
And both the way you presented above and the way I posted the question, Style's request is being ignored
I also thought it might be from the OS, but for example if I write this it works, this is an improved form I copied from wxSmith

Code: Select all

wxStatusBar* StatusBar = new wxStatusBar(this);
      StatusBar->SetFieldsCount(1);
      StatusBar->SetStatusText("Field 1", 0);
      
      int Style[] = {wxSB_SUNKEN};
      StatusBar->SetStatusStyles(1, Style);
      SetStatusBar(StatusBar);
And trying to use the wxFrame command it ignores any style.

Code: Select all

CreateStatusBar(3, wxSTB_DEFAULT_STYLE | wxSB_SUNKEN);
CreateStatusBar(3, wxSB_SUNKEN);
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Statusbar Beginner

Post by ONEEYEMAN »

Hi,
It is possible that the status bar is such a unique control that changing the style on ht efly simply doesn't work.
You best bet is to re-create the status bar with the appropriate style. ALWAYS!!!

Also, keep in mind that not all styles can be changed on the fly.
Check the documentation - it explicitly says so. But my guess is that for status bar it is applicable to all of them, because the status bar is such a unique control.

Thank you.
Post Reply