Long text only displays last part in 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
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Long text only displays last part in wxTextCtrl

Post by Ronald »

text_ctrl.png
text_ctrl.png (8.77 KiB) Viewed 1240 times
code in parent dialog constructor

Code: Select all

__tc_path->SetLabelText(wxT("123456789abcdefghijklmnopqrstuvwxyz"));
__tc_path->SetInsertionPoint(0);
__tc_path->SelectNone();
code to show the parent dialog, the default size if 800 x 600

Code: Select all

DebugDialog dlg(this);
dlg.Center();
dlg.Maximize();
dlg.ShowModal();
How to the full text in text ctrl? Better if the text is not selected by defautl.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Long text only displays last part in wxTextCtrl

Post by doublemax »

Try SetValue() instead of SetLabelText()
Use the source, Luke!
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Re: Long text only displays last part in wxTextCtrl

Post by Ronald »

doublemax wrote: Mon Jan 04, 2021 5:56 am Try SetValue() instead of SetLabelText()
The result is same.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Long text only displays last part in wxTextCtrl

Post by doublemax »

How do you construct the wxTextCtrl? What's its size? Does it cover the whole visible area?
Use the source, Luke!
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Re: Long text only displays last part in wxTextCtrl

Post by Ronald »

doublemax wrote: Mon Jan 04, 2021 6:59 am How do you construct the wxTextCtrl? What's its size? Does it cover the whole visible area?

Code: Select all

wxBoxSizer * pSizer_0 = new wxBoxSizer(wxVERTICAL);

{
    wxBoxSizer * pSizer_0_0 = new wxBoxSizer(wxHORIZONTAL);

    __tc_path = new wxTextCtrl(this, wxID_ANY);
    pSizer_0_0->Add(__tc_path, 1, wxEXPAND);

    __btn_choose_file_and_run = new wxButton(this, CTRL_ID_CHOOSE_FILE_AND_RUN, wxT("Choose File && Run"));
    pSizer_0_0->Add(__btn_choose_file_and_run);

    pSizer_0_0->AddSpacer(10);

    __btn_run = new wxButton(this, CTRL_ID_RUN, wxT("Run"));
    pSizer_0_0->Add(__btn_run);

    pSizer_0_0->AddSpacer(10);

    __btn_first_page = new wxButton(this, CTRL_ID_FIRST_PAGE, wxT("First"));
    pSizer_0_0->Add(__btn_first_page);

    __btn_prev_page = new wxButton(this, CTRL_ID_PREV_PAGE, wxT("Prev"));
    pSizer_0_0->Add(__btn_prev_page);

    __btn_next_page = new wxButton(this, CTRL_ID_NEXT_PAGE, wxT("Next"));
    pSizer_0_0->Add(__btn_next_page);

    __btn_last_page = new wxButton(this, CTRL_ID_LAST_PAGE, wxT("Last"));
    pSizer_0_0->Add(__btn_last_page);

    pSizer_0->Add(pSizer_0_0, 0, wxEXPAND);
}

{
    wxBoxSizer * pSizer_0_1 = new wxBoxSizer(wxHORIZONTAL);

    __log_ctrl = new LogCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(600, -1));
    pSizer_0_1->Add(__log_ctrl, 0, wxEXPAND);

    __annotated_page_wnd = new AnnotatedPageWnd(this);
    __annotated_page_wnd->Config(Global::config.annotation_display_config);
    pSizer_0_1->Add(__annotated_page_wnd, 1, wxEXPAND);

    pSizer_0->Add(pSizer_0_1, 1, wxEXPAND);
}

this->SetSizer(pSizer_0);

__tc_path->SetValue (wxT("123456789abcdefghijklmnopqrstuvwxyz"));
__tc_path->SetInsertionPoint(0);
__tc_path->SelectNone();
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: Long text only displays last part in wxTextCtrl

Post by doublemax@work »

Too me it looks like the textcontrol is just too small. Try editing the text manually to confirm

Is that real code, are you setting the value of the textcontrol after setting the sizer? Try calling Layout() afterwards.

BTW: There is a special control for that purpose (display filepath and "select file" button), wxFilePickerCtrl
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Re: Long text only displays last part in wxTextCtrl

Post by Ronald »

doublemax@work wrote: Mon Jan 04, 2021 10:25 am Too me it looks like the textcontrol is just too small. Try editing the text manually to confirm
Is that real code, are you setting the value of the textcontrol after setting the sizer? Try calling Layout() afterwards.
Real code. The dialog's default size in ctor is 800 x 600. The way it is shown is as below:

Code: Select all

DebugDialog dlg(this);
dlg.Center();
dlg.Maximize();
dlg.ShowModal();
After calling Layout before setting the value of the text ctrl in the dialog's ctor,
the problem is the same essentially, only more but not all letters are shown.
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Re: Long text only displays last part in wxTextCtrl

Post by Ronald »

Reproduce the problem in minimal.cpp in samples of wxWidgets

Code: Select all

#include "wx/wx.h"

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

class MyFrame : public wxFrame
{
public:
    // ctor(s)
    MyFrame(const wxString & title);

private:
    wxTextCtrl * __tc_test;

private:
    // event handlers (these functions should _not_ be virtual)
    void OnQuit(wxCommandEvent & event);
    void OnAbout(wxCommandEvent & event);

private:
    // any class wishing to process wxWidgets events must use this macro
    wxDECLARE_EVENT_TABLE();
};

// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------

// IDs for the controls and the menu commands
enum
{
    Minimal_Quit = wxID_EXIT,
    Minimal_About = wxID_ABOUT
};

wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
EVT_MENU(Minimal_About, MyFrame::OnAbout)
wxEND_EVENT_TABLE()

wxIMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
    // call the base class initialization method, currently it only parses a
    // few common command-line options but it could be do more in the future
    if (!wxApp::OnInit())
        return false;

    // create the main application window
    MyFrame * frame = new MyFrame("Minimal wxWidgets App");

    // and show it (the frames, unlike simple controls, are not shown when
    // created initially)
    frame->Show(true);

    // success: wxApp::OnRun() will be called which will enter the main message
    // loop and the application will run. If we returned false here, the
    // application would exit immediately.
    return true;
}

// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------

MyFrame::MyFrame(const wxString & title)
    : wxFrame(NULL, wxID_ANY, title)
{
#if wxUSE_MENUBAR
    // create a menu bar
    wxMenu * fileMenu = new wxMenu;

    // the "About" item should be in the help menu
    wxMenu * helpMenu = new wxMenu;
    helpMenu->Append(Minimal_About, "&About\tF1", "Show about dialog");

    fileMenu->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program");

    // now append the freshly created menu to the menu bar...
    wxMenuBar * menuBar = new wxMenuBar();
    menuBar->Append(fileMenu, "&File");
    menuBar->Append(helpMenu, "&Help");

    // ... and attach this menu bar to the frame
    SetMenuBar(menuBar);
#else // !wxUSE_MENUBAR
    // If menus are not available add a button to access the about box
    wxSizer * sizer = new wxBoxSizer(wxHORIZONTAL);
    wxButton * aboutBtn = new wxButton(this, wxID_ANY, "About...");
    aboutBtn->Bind(wxEVT_BUTTON, &MyFrame::OnAbout, this);
    sizer->Add(aboutBtn, wxSizerFlags().Center());
    SetSizer(sizer);
#endif // wxUSE_MENUBAR/!wxUSE_MENUBAR

#if wxUSE_STATUSBAR
    // create a status bar just for fun (by default with 1 pane only)
    CreateStatusBar(2);
    SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR


    wxBoxSizer * pSizer_0 = new wxBoxSizer(wxVERTICAL);
    {
        wxBoxSizer * pSizer_0_0 = new wxBoxSizer(wxHORIZONTAL);
        
        __tc_test = new wxTextCtrl(this, wxID_ANY);
        pSizer_0_0->Add(__tc_test, 1, wxEXPAND);

        pSizer_0->Add(pSizer_0_0, 0, wxEXPAND);
    }

    this->SetSizer(pSizer_0);
    __tc_test->SetValue(wxT("123456789abcdefghijklmnopqrstuvwxyz"));
}


// event handlers

void MyFrame::OnQuit(wxCommandEvent & WXUNUSED(event))
{
    // true is to force the frame to close
    Close(true);
}

void MyFrame::OnAbout(wxCommandEvent & WXUNUSED(event))
{
    wxMessageBox(wxString::Format
    (
        "Welcome to %s!\n"
        "\n"
        "This is the minimal wxWidgets sample\n"
        "running under %s.",
        wxVERSION_STRING,
        wxGetOsDescription()
    ),
                 "About wxWidgets minimal sample",
                 wxOK | wxICON_INFORMATION,
                 this);
}
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Long text only displays last part in wxTextCtrl

Post by Kvaz1r »

Just do what doublemax said earlier - add Layout() after changing of widgets state:

Code: Select all

__tc_test->SetValue(wxT("123456789abcdefghijklmnopqrstuvwxyz"));
this->Layout();
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: Long text only displays last part in wxTextCtrl

Post by doublemax@work »

I tried it and can confirm the strange behavior. It's also strange that i've never seen this before...

But i haven't found a workaround yet.
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Re: Long text only displays last part in wxTextCtrl

Post by Ronald »

Kvaz1r wrote: Mon Jan 04, 2021 1:31 pm Just do what doublemax said earlier - add Layout() after changing of widgets state:

Code: Select all

__tc_test->SetValue(wxT("123456789abcdefghijklmnopqrstuvwxyz"));
this->Layout();
After calling Layout before setting the value of the text ctrl in the dialog's ctor,
the problem is the same essentially, only more but not all letters are shown.
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Re: Long text only displays last part in wxTextCtrl

Post by Ronald »

doublemax@work wrote: Mon Jan 04, 2021 2:56 pm I tried it and can confirm the strange behavior. It's also strange that i've never seen this before...

But i haven't found a workaround yet.
Thanks, I'll report the problem.
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Long text only displays last part in wxTextCtrl

Post by Kvaz1r »

Ronald wrote: Tue Jan 05, 2021 2:57 am After calling Layout before setting the value of the text ctrl in the dialog's ctor,
the problem is the same essentially, only more but not all letters are shown.
There is definitely something that I not understand - I can't reproduce behaviour with your minimal code if add Layout in the most bottom of constructor. I'm on Win10. Let's wait for answer from developers - I see you've opened a ticket - wxTextCtrl only shows last part
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Re: Long text only displays last part in wxTextCtrl

Post by Ronald »

Kvaz1r wrote: Tue Jan 05, 2021 9:14 am I can't reproduce behaviour with your minimal code if add Layout in the most bottom of constructor.
Yes. If making the text longer and show the frame maximized, it can be reproduce.

Code: Select all

#include "wx/wx.h"

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

class MyFrame : public wxFrame
{
public:
    // ctor(s)
    MyFrame(const wxString & title);

private:
    wxTextCtrl * __tc_test;

private:
    // event handlers (these functions should _not_ be virtual)
    void OnQuit(wxCommandEvent & event);
    void OnAbout(wxCommandEvent & event);

private:
    // any class wishing to process wxWidgets events must use this macro
    wxDECLARE_EVENT_TABLE();
};

// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------

// IDs for the controls and the menu commands
enum
{
    Minimal_Quit = wxID_EXIT,
    Minimal_About = wxID_ABOUT
};

wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
EVT_MENU(Minimal_About, MyFrame::OnAbout)
wxEND_EVENT_TABLE()

wxIMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
    // call the base class initialization method, currently it only parses a
    // few common command-line options but it could be do more in the future
    if (!wxApp::OnInit())
        return false;

    // create the main application window
    MyFrame * frame = new MyFrame("Minimal wxWidgets App");

    frame->Maximize();

    // and show it (the frames, unlike simple controls, are not shown when
    // created initially)
    frame->Show(true);

    // success: wxApp::OnRun() will be called which will enter the main message
    // loop and the application will run. If we returned false here, the
    // application would exit immediately.
    return true;
}

// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------

MyFrame::MyFrame(const wxString & title)
    : wxFrame(NULL, wxID_ANY, title)
{
#if wxUSE_MENUBAR
    // create a menu bar
    wxMenu * fileMenu = new wxMenu;

    // the "About" item should be in the help menu
    wxMenu * helpMenu = new wxMenu;
    helpMenu->Append(Minimal_About, "&About\tF1", "Show about dialog");

    fileMenu->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program");

    // now append the freshly created menu to the menu bar...
    wxMenuBar * menuBar = new wxMenuBar();
    menuBar->Append(fileMenu, "&File");
    menuBar->Append(helpMenu, "&Help");

    // ... and attach this menu bar to the frame
    SetMenuBar(menuBar);
#else // !wxUSE_MENUBAR
    // If menus are not available add a button to access the about box
    wxSizer * sizer = new wxBoxSizer(wxHORIZONTAL);
    wxButton * aboutBtn = new wxButton(this, wxID_ANY, "About...");
    aboutBtn->Bind(wxEVT_BUTTON, &MyFrame::OnAbout, this);
    sizer->Add(aboutBtn, wxSizerFlags().Center());
    SetSizer(sizer);
#endif // wxUSE_MENUBAR/!wxUSE_MENUBAR

#if wxUSE_STATUSBAR
    // create a status bar just for fun (by default with 1 pane only)
    CreateStatusBar(2);
    SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR


    wxBoxSizer * pSizer_0 = new wxBoxSizer(wxVERTICAL);
    {
        wxBoxSizer * pSizer_0_0 = new wxBoxSizer(wxHORIZONTAL);
        
        __tc_test = new wxTextCtrl(this, wxID_ANY);
        pSizer_0_0->Add(__tc_test, 1, wxEXPAND);

        pSizer_0->Add(pSizer_0_0, 0, wxEXPAND);
    }

    this->SetSizer(pSizer_0);

    Layout();

    __tc_test->SetValue(wxT("123456789abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz"));
}


// event handlers

void MyFrame::OnQuit(wxCommandEvent & WXUNUSED(event))
{
    // true is to force the frame to close
    Close(true);
}

void MyFrame::OnAbout(wxCommandEvent & WXUNUSED(event))
{
    wxMessageBox(wxString::Format
    (
        "Welcome to %s!\n"
        "\n"
        "This is the minimal wxWidgets sample\n"
        "running under %s.",
        wxVERSION_STRING,
        wxGetOsDescription()
    ),
                 "About wxWidgets minimal sample",
                 wxOK | wxICON_INFORMATION,
                 this);
}
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Long text only displays last part in wxTextCtrl

Post by Kvaz1r »

Now I see, thanks. It's related to something new, because in 3.1.3 works as expected.
Post Reply