SetDefaultStyle to wxTextCtrl Not Working. 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

SetDefaultStyle to wxTextCtrl Not Working.

Post by Harsh »

Copy pasted code from documentation for SetDefaultStyle but not working.

Code: Select all

#include<wx/wx.h>

class MyFrame : public wxFrame{
	wxPanel *panel;
    	wxBoxSizer *vbox;
	wxTextCtrl *txt;
	
public : 
	MyFrame():wxFrame(NULL,wxID_ANY,"Child Focus"){

		panel=new wxPanel(this);
		vbox=new wxBoxSizer(wxVERTICAL);

		txt=new wxTextCtrl(panel,wxID_ANY,wxT(""),wxDefaultPosition,wxDefaultSize,wxTE_MULTILINE);
		txt->SetHint("Hint");
		txt->SetDefaultStyle(wxTextAttr(*wxRED));
		txt->AppendText("Red text\n");
		txt->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
		txt->AppendText("Red on grey text\n");
		txt->SetDefaultStyle(wxTextAttr(*wxBLUE));
		txt->AppendText("Blue on grey text\n");
		vbox->Add(txt,0,wxEXPAND|wxALL,5);

		panel->SetSizer(vbox);
	}
};

class MyApp: public wxApp
{
    wxFrame* m_frame;
public:
    
    bool OnInit()
    {
        m_frame = new MyFrame();
        m_frame->Show();
        return true;
    } 
    
};
IMPLEMENT_APP(MyApp);
What is wrong here.
Attachments
style.png
style.png (4.16 KiB) Viewed 2059 times
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: SetDefaultStyle to wxTextCtrl Not Working.

Post by doublemax »

[Thanks for providing a minimal, compilable sample!]

You need to add the wxTE_RICH or wxTE_RICH2 style flag when creating the wxTextCtrl.
Use the source, Luke!
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

Re: SetDefaultStyle to wxTextCtrl Not Working.

Post by Harsh »

doublemax wrote: Wed Jun 30, 2021 3:14 pm [Thanks for providing a minimal, compilable sample!]

You need to add the wxTE_RICH or wxTE_RICH2 style flag when creating the wxTextCtrl.
I am using theme on plain wxtextctrl. x foreground, y background colour.
On creation hint remains as foreground colour
but on focus out became gray again. Any suggestion?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: SetDefaultStyle to wxTextCtrl Not Working.

Post by ONEEYEMAN »

Hi,
Ate you making HTML editor?
If not - maybe you can use wxWebVirew?

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

Re: SetDefaultStyle to wxTextCtrl Not Working.

Post by Harsh »

ONEEYEMAN wrote: Wed Jun 30, 2021 9:02 pm Hi,
Ate you making HTML editor?
If not - maybe you can use wxWebVirew?

Thank you.
I just changed plain wxtextfield foreground and background as indication, that it meet certain condition. But it's text colour remains same for empty field. It shows old text colour if add text in it after changes applied.
Those fields which has text before changes applied gets the colour right.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: SetDefaultStyle to wxTextCtrl Not Working.

Post by ONEEYEMAN »

Hi,
Can you show the screenshot and post the code?

It is very hard to understand what you mean and what you want to achieve.

As I said - if you don't need the editing, try the wxWebView.

Thank you.
Post Reply