How to change the caret for a wxTextCtrl?

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
gasko
Earned a small fee
Earned a small fee
Posts: 11
Joined: Mon Apr 13, 2020 11:14 am

How to change the caret for a wxTextCtrl?

Post by gasko »

I've tried changing the caret for a wxTextCtrl the same way they do in the wxCaret demo, however have had no luck. This is my code:

Code: Select all

#include "wx/wx.h"
#include "wx/caret.h"
#include "wx/textctrl.h"

class MyApp : public wxApp
{
public:
    virtual bool OnInit() wxOVERRIDE;
};

wxIMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
    wxFrame* myFrame = new wxFrame(nullptr, wxID_ANY, "Caret test", wxPoint(50, 50), wxSize(450, 340));
    wxPanel* panel = new wxPanel(myFrame);
    wxTextCtrl* ctrl = new wxTextCtrl(panel, wxID_ANY, "Empty text");

    wxCaret* caret = new wxCaret(ctrl, 10, 18);
    ctrl->SetCaret(caret);
    caret->Move(1, 1);
    caret->Show();

    myFrame->Show();
    return true;
}
The documentation for wxCaret says "Text controls usually have their own caret but wxCaret provides a way to use a caret in other windows."

How can I change the caret for a text control?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: How to change the caret for a wxTextCtrl?

Post by PB »

I think wxCaret is for controls that do not have their own. wxTextCtrl already has a caret:
wxWidgets documentation wrote:Text controls usually have their own caret but wxCaret provides a way to use a caret in other windows.
I think wxTextCtrl's caret cannot be changed (at least not via its metods), the native control takes care of that. AFAIK, at least on Windows the native control does not allow changing caret properties.
Post Reply