Why are my wxButtons always flat

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
Ged 512
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Dec 13, 2019 2:02 am

Why are my wxButtons always flat

Post by Ged 512 »

My wxButtons never have raised borders nor do they change when clicked on. I just have grey rectangles.
My typical wxSmith generated code is:

AXIAL0 = new wxButton(MainSeite, ID_BUTTON2, _("Axial=0"), wxPoint(90,420), wxSize(150,30), 0, wxDefaultValidator, _T("ID_BUTTON2"));
AXIAL0->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_SCROLLBAR));

I am using Windows 10 and wxWidgets 3.1.1 or Raspian Linux and WxWidgets 3.0.4.

What do I do wrong?
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Why are my wxButtons always flat

Post by catalin »

Ged 512 wrote: Tue May 05, 2020 1:38 am AXIAL0->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_SCROLLBAR));

What do I do wrong?
This is what you are doing wrong.
By setting a custom background color you lose the native look (any gradient / 3D effect that native drawing had). Just don't do it.
Ged 512
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Dec 13, 2019 2:02 am

Re: Why are my wxButtons always flat

Post by Ged 512 »

Sorry,
but I made a new button TEST without setting the background color and it is just as flat.
wxSmith code:

TEST = new wxButton(ExtSeite, ID_BUTTON14, _("Test"), wxPoint(700,500), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON14"));
BoxSizer1->Add(ExtSeite, 1, wxALL|wxEXPAND, 5);

Additionaly I entered the sample code from the book "GUI Programming with wxWidgets" page 86:

wxButton* button = new wxButton(ExtSeite, wxID_OK, wxT("OK"),wxPoint(10,10), wxDefaultSize);

This button is also flat. What else can I do?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Why are my wxButtons always flat

Post by ONEEYEMAN »

Hi,
Which platform? Which wx version?
Do you use any non-default theme?
Do you see the flat button inside the wxSmith or when you actually executing your code?

Thank you.
Ged 512
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Dec 13, 2019 2:02 am

Re: Why are my wxButtons always flat

Post by Ged 512 »

To answer your questions:

I am using Windows 10 and wxWidgets 3.1.3 or Raspian Linux and WxWidgets 3.0.4. Codeblocks 17.12 and wxSmith.
My buttons are flat inside wxSmith and with my executed code.
Sorry, I don't know what a theme is and certainly don't use a non-default theme.
Below is the code of one of my Notebook pages. The entire constructor is generated by wxSmith. The reset wxButtons is flat.

Code: Select all

#include "wx_pch.h"
#include "DiaPanel.h"
#include "GlobalData.h"
#include "SpiPanel.h"

#ifndef WX_PRECOMP
	//(*InternalHeadersPCH(DiaPanel)
	#include <wx/intl.h>
	#include <wx/string.h>
	//*)
#endif
//(*InternalHeaders(DiaPanel)
#include <wx/settings.h>
//*)

//(*IdInit(DiaPanel)
const long DiaPanel::ID_BUTTON_RESET = wxNewId();
const long DiaPanel::ID_PANEL1 = wxNewId();
//*)

//========================================================== global data
extern GlobalData Dat;

BEGIN_EVENT_TABLE(DiaPanel,wxPanel)
	//(*EventTable(DiaPanel)
	//*)
END_EVENT_TABLE()

DiaPanel::DiaPanel(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
	//(*Initialize(DiaPanel)
	wxBoxSizer* BoxSizer1;

	Create(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("id"));
	SetBackgroundColour(wxColour(240,238,224));
	BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
	DiaSeite = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
	DiaSeite->SetBackgroundColour(wxColour(240,238,224));
	RESET = new wxButton(DiaSeite, ID_BUTTON_RESET, _("Reset"), wxPoint(450,100), wxSize(150,30), 0, wxDefaultValidator, _T("ID_BUTTON_RESET"));
	RESET->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_SCROLLBAR));
	BoxSizer1->Add(DiaSeite, 1, wxALL|wxEXPAND, 5);
	SetSizer(BoxSizer1);
	BoxSizer1->Fit(this);
	BoxSizer1->SetSizeHints(this);

	Connect(ID_BUTTON_RESET,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&DiaPanel::OnRESETClick);
	DiaSeite->Connect(wxEVT_PAINT,(wxObjectEventFunction)&DiaPanel::OnDiaSeitePaint,0,this);
	//*)
}

DiaPanel::~DiaPanel()
{
	//(*Destroy(DiaPanel)
	//*)
}

void DiaPanel::PeriodicUpdate()                        // update page
{

    //------------------------------------------------------ repaint display
    DiaSeite->Refresh(true);
}

#define Dia_X           10
#define Dia_Y           20
#define Dia_DY          23
#define Dia_Pitch_X     0
#define Dia_Pitch_Y     300

void DiaPanel::OnDiaSeitePaint(wxPaintEvent& event)
{
    Dat.Page = PitchPage;
    wxPaintDC dc(DiaSeite);
    wxString TextBuf;
    dc.SetTextForeground(*wxBLACK);                 // Set the text foreground to black
    dc.SetTextBackground(*wxWHITE);                 // Set the text background to white
    wxFont MyBigFont(30,wxFONTFAMILY_TELETYPE,wxNORMAL,wxBOLD,false);
    wxFont MyMidFont(20,wxFONTFAMILY_TELETYPE,wxNORMAL,wxBOLD,false);
    dc.SetPen(*wxBLACK_PEN);
    //---------------------------------------------------- test data
    dc.DrawLine(0,570,1320,570);
    dc.DrawLine(1320,0,1320,570);
    //---------------------------------------------------- explanations
    int TempY =Dia_Y;
    dc.DrawText("Pitch measurement"                                    ,Dia_X,TempY);TempY+=Dia_DY;
    dc.DrawText("Complete lathe pitch selection"                       ,Dia_X,TempY);TempY+=Dia_DY;
    dc.DrawText("Make sure the saddle has enough space for 20 turns"   ,Dia_X,TempY);TempY+=Dia_DY;
    dc.DrawText("Set lathe to low speed and engage lock nut"           ,Dia_X,TempY);TempY+=Dia_DY;
    dc.DrawText("Click Reset to clear pitch data"                      ,Dia_X,TempY);TempY+=Dia_DY;
    dc.DrawText("Switch lathe on and wait for pitch readings to update",Dia_X,TempY);TempY+=Dia_DY;
    //------------------------------------------------------------------------------------------------ pitch
    dc.SetFont(MyBigFont);
    if(Dat.fPitch>0.1) TextBuf.Printf("%8.2f mm/turn %8.2f turns/inch",Dat.fPitch,25.4/Dat.fPitch);
        else           TextBuf.Printf("                                     ");
    dc.DrawText(TextBuf,Dia_Pitch_X,Dia_Pitch_Y);
}

void DiaPanel::OnRESETClick(wxCommandEvent& event)
{
    Dat.Command = C_ResPitch;
}
Last edited by catalin on Thu May 07, 2020 6:53 am, edited 1 time in total.
Reason: code tags
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Why are my wxButtons always flat

Post by ONEEYEMAN »

Hi,
So, it happens both within wxSmith and when your execute your compiled code.
And it happens in both Windows and Linux.

Can you build and ran the notebook sample and see if the problem is there?

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

Re: Why are my wxButtons always flat

Post by doublemax »

Can you show a screenshot. Try building the "widgets" sample that comes with wxWidgets and check how it looks.
Use the source, Luke!
Ged 512
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Dec 13, 2019 2:02 am

Re: Why are my wxButtons always flat

Post by Ged 512 »

How do I send a screenshot to this forum? If you provide your email address, I can email you images.

I made some progress: My wxButtons behave better with both foreground and background color used as default:

ENGAGED = new wxButton(IntSeite, ID_BUTTON1, _("Engaged"), wxPoint(320,168), wxSize(150,30), 0, wxDefaultValidator, _T("ID_BUTTON1"));

Now my buttons become darker when hovering over it and more dark when clicking on it. However they still do not have a raised border.

I tried the sample code from the book "GUI Programming with wxWidgets" page 86:

wxButton* button = new wxButton(ExtSeite, wxID_OK, wxT("OK"),wxPoint(10,10), wxDefaultSize);

It can be simpler than this. This button is also flat.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Why are my wxButtons always flat

Post by doublemax »

When you create a post, there is an option at the bottom to add attachments. If you attach an image, you get the option to display it inline.

I was asking for a screenshot, because under Windows 10, buttons *do* look flat. I think what you're seeing is totally fine.

Just open any standard application, e.g. MS Paint and find the settings/properties dialog for comparison.
Use the source, Luke!
Ged 512
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Dec 13, 2019 2:02 am

Re: Why are my wxButtons always flat

Post by Ged 512 »

Thanks,

I have attached a screenshot of my wxButtons and for comparison buttons made with MS VisualC6.

Please comment.
Attachments
VisualC6.png
VisualC6.png (515 Bytes) Viewed 2000 times
wxButtons.png
wxButtons.png (2.92 KiB) Viewed 2000 times
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Why are my wxButtons always flat

Post by ONEEYEMAN »

Hi,
Is it a screenshot from the wxSmith (or whatever other RAD tool you use)?
Or this is a screenshot from the running the binary you produced?

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

Re: Why are my wxButtons always flat

Post by doublemax »

I have attached a screenshot of my wxButtons and for comparison buttons made with MS VisualC6.
The flat version is the correct one under Windows 10. You'll get the old "Windows 95" style buttons if your executable doesn't have a proper manifest. This probably happens when you build it with VC6.
Use the source, Luke!
Ged 512
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Dec 13, 2019 2:02 am

Re: Why are my wxButtons always flat

Post by Ged 512 »

Thanks for all your help.

It looks like I was chasing ghosts.
Post Reply