SetBackgroundColour do not work on wxBORDER_SUNKEN Topic is solved

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
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

SetBackgroundColour do not work on wxBORDER_SUNKEN

Post by Harsh »

In Code Below, SetBackgroundColour applied when wxBORDER_NONE, but on wxBORDER_SUNKEN it shows no effect.
I need border because I do not know how to apply padding in wxWidgets.

Code: Select all

#include<wx/frame.h>
#include<wx/listctrl.h>
#include<wx/app.h>
#include<wx/sizer.h>
#include<wx/panel.h>
#include<wx/button.h>

class MyFrame : public wxFrame{
	    wxPanel *panel;
        wxFrame *list;
        wxBoxSizer *vbox;
        wxButton *btn;
        wxTextCtrl *txt;
        wxRect rect;
        int flag=0,flag1=0;
		
public : 
	MyFrame():wxFrame(NULL,wxID_ANY,"Child Focus"){
		vbox=new wxBoxSizer(wxVERTICAL);

    btn=new wxButton(this,wxID_ANY,wxT("Button"),wxDefaultPosition,wxDefaultSize,wxBORDER_SUNKEN|wxBU_LEFT);
    //Change Above, wxBORDER_SUNKEN TO wxBORDER_NONE
    btn->Bind(wxEVT_ENTER_WINDOW,&OnEnter,this);
    btn->Bind(wxEVT_LEAVE_WINDOW,&OnLeave,this);
    vbox->Add(btn,0,wxEXPAND|wxALL,5);

    SetSizer(vbox);

}
	void OnEnter(wxMouseEvent &event){
		btn=wxDynamicCast(event.GetEventObject(),wxButton);
		btn->SetBackgroundColour(wxColour("#FBC403"));
		btn->SetForegroundColour(wxColour("#000000"));
		this->Refresh();
	}
	void OnLeave(wxMouseEvent &event){
		btn=wxDynamicCast(event.GetEventObject(),wxButton);
		btn->SetBackgroundColour(wxColour("#000000"));
		btn->SetForegroundColour(wxColour("#FBC403"));
		this->Refresh();
	}
};

class MyApp: public wxApp
{
    wxFrame* m_frame;
public:
    
    bool OnInit()
    {
        m_frame = new MyFrame();
        m_frame->Show();
        return true;
    } 
    
};

IMPLEMENT_APP(MyApp);
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: SetBackgroundColour do not work on wxBORDER_SUNKEN

Post by ONEEYEMAN »

Hi,
What is your wx version?
What platform/toolkit?

Also, when you have only one child - this child cover the who;e client area of the frame (or TLW).

Please consider creating more control and post the full code.
And you don't have to include all those header files - all you need to include is wx.h.

Thank you.
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

Re: SetBackgroundColour do not work on wxBORDER_SUNKEN

Post by Harsh »

ONEEYEMAN wrote: Wed May 12, 2021 9:50 pm What is your wx version?
What platform/toolkit?
Version : 3.1.4
Platform : wxMSW (Windows10)

No. It doesn't fill TLW.
I have created multiple buttons in vbox at first place. Same result.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: SetBackgroundColour do not work on wxBORDER_SUNKEN

Post by ONEEYEMAN »

Hi,
Can you st a screenshot with one button and post the code and the screenshot with multiple?

Thank you.
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

Re: SetBackgroundColour do not work on wxBORDER_SUNKEN

Post by Harsh »

ONEEYEMAN wrote: Thu May 13, 2021 1:46 pm Can you st a screenshot with one button and post the code and the screenshot with multiple?
Code is above in question and Here are two images.

Hope this will help.
Attachments
Just Changed Flag to wxBORDER_SUNKEN
Just Changed Flag to wxBORDER_SUNKEN
WithBorderSunken.png (4.54 KiB) Viewed 1415 times
Just Changed Flag to wxBORDER_NONE
Just Changed Flag to wxBORDER_NONE
WithBorderNone.png (5.18 KiB) Viewed 1415 times
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: SetBackgroundColour do not work on wxBORDER_SUNKEN

Post by ONEEYEMAN »

Hi,
And what do you expect to see in the second one (or the first one)?

Also - please add more controls and post the code with the image.

Thank you.
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

Re: SetBackgroundColour do not work on wxBORDER_SUNKEN

Post by Harsh »

ONEEYEMAN wrote: Thu May 13, 2021 5:14 pm
And what do you expect to see in the second one (or the first one)?

Also - please add more controls and post the code with the image.
Flag : wxBORDER_NONE Changed background colour, But no flag button (Default Button) and other flags just keep background colour white and border blue on wxEVT_ENTER_EVENT. Isn't it a bug? I just want to confirm it before posting it in bug section.

And

How can I change border colour and give padding-left to button.
I know, it is not possible with native-gui. But if there is any trick then let me know?
Attachments
MultipleButtons.png
MultipleButtons.png (9.96 KiB) Viewed 1409 times
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

Re: SetBackgroundColour do not work on wxBORDER_SUNKEN

Post by Harsh »

ONEEYEMAN wrote: Thu May 13, 2021 5:14 pm
Also - please add more controls and post the code with the image.
Code is in question. And here is another code for third image.

Code: Select all

#include<wx/wx.h>

class MyFrame : public wxFrame{
	    wxPanel *panel;
        wxBoxSizer *vbox;
		wxStaticText *st;
        wxButton *btn;
        int i=0;
		
public : 
	MyFrame():wxFrame(NULL,wxID_ANY,"Child Focus"){
		vbox=new wxBoxSizer(wxVERTICAL);

	vbox->Add(new wxStaticText(this,wxID_ANY,wxT("Default Button")));
	for(i=0;i<5;i++){
		btn=new wxButton(this,wxID_ANY,wxT("Button"));
		btn->Bind(wxEVT_ENTER_WINDOW,&OnEnter,this);
		btn->Bind(wxEVT_LEAVE_WINDOW,&OnLeave,this);
		vbox->Add(btn,0,wxEXPAND|wxALL,5);
	}
	
	vbox->Add(new wxStaticText(this,wxID_ANY,wxT("Border NONE Button")));
	for(i=0;i<5;i++){
		btn=new wxButton(this,wxID_ANY,wxT("Button"),wxDefaultPosition,wxDefaultSize,wxBU_LEFT|wxBORDER_NONE);
		btn->Bind(wxEVT_ENTER_WINDOW,&OnEnter,this);
		btn->Bind(wxEVT_LEAVE_WINDOW,&OnLeave,this);
		vbox->Add(btn,0,wxEXPAND|wxALL,5);
	}
	
	vbox->Add(new wxStaticText(this,wxID_ANY,wxT("Border SUNKEN Button")));
	for(i=0;i<5;i++){
		btn=new wxButton(this,wxID_ANY,wxT("Button"),wxDefaultPosition,wxDefaultSize,wxBU_LEFT|wxBORDER_SUNKEN);
		btn->Bind(wxEVT_ENTER_WINDOW,&OnEnter,this);
		btn->Bind(wxEVT_LEAVE_WINDOW,&OnLeave,this);
		vbox->Add(btn,0,wxEXPAND|wxALL,5);
	}
    SetSizer(vbox);

}
	void OnEnter(wxMouseEvent &event){
		btn=wxDynamicCast(event.GetEventObject(),wxButton);
		btn->SetBackgroundColour(wxColour("#FBC403"));
		btn->SetForegroundColour(wxColour("#000000"));
		this->Refresh();
	}
	void OnLeave(wxMouseEvent &event){
		btn=wxDynamicCast(event.GetEventObject(),wxButton);
		btn->SetBackgroundColour(wxColour("#000000"));
		btn->SetForegroundColour(wxColour("#FBC403"));
		this->Refresh();
	}
};

class MyApp: public wxApp
{
    wxFrame* m_frame;
public:
    
    bool OnInit()
    {
        m_frame = new MyFrame();
        m_frame->Show();
        return true;
    } 
    
};

IMPLEMENT_APP(MyApp);
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: SetBackgroundColour do not work on wxBORDER_SUNKEN

Post by ONEEYEMAN »

Hi,
For the padding you can use wx{Stretch}Spacer. Just add either stretchspacer or some space with the wxEXPAND flag.

In terms of colour and border - it is possible.
You can file a bug at trac.wxwidgets.org.

Thank you.
Post Reply