Is it normal for the Hints not to reappear? 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
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Is it normal for the Hints not to reappear? wxTextCtrl

Post by Nick » Sun May 03, 2020 9:12 am

I was wondering if I was doing something wrong!
I build wxTextCtrl the way below, creating the Hint and everything works when the wxFrame is shown

Code: Select all

EdName = new wxTextCtrl(TabContacts, wxID_ANY, wxEmptyString, wxPoint(190,45), wxSize(300,30));
EdName->SetMaxLength(250);
EdName->SetHint("Name");
Then I click a button to clear the wxTextCtrl with the command below, but by doing that, the Hints disappear completely.
And I thought that if the wxTextCtrl no longer has text, the hints would be shown!

Code: Select all

EdName->SetValue("");

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4058
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Is it normal for the Hints not to reappear? wxTextCtrl

Post by ONEEYEMAN » Mon May 04, 2020 12:05 am

Hi,
What if you start the program, go to the text control type something and then backspace the text?
Will it show then?

Thank you.

Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Is it normal for the Hints not to reappear? wxTextCtrl

Post by Nick » Mon May 04, 2020 2:24 pm

ONEEYEMAN wrote:
Mon May 04, 2020 12:05 am
Hi,
What if you start the program, go to the text control type something and then backspace the text?
Will it show then?

Thank you.
I created an example with 4 TextCtrl to test! Then after your answer I discovered that: When executing the command

Code: Select all

   TextCtrl1->SetValue("");
   TextCtrl2->SetValue("");
   TextCtrl3->SetValue("");
   TextCtrl4->SetValue("");
He erases all the hints. But if I navigate the TAB between the controls the Hints are restored.
Is there any way I can restore those hints without having to get in and out of control? Like a general Refresh for all TextCtrl?
Because there are TextCtrl in other wxNotebook tabs, there are 4 tabs in total!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2387
Joined: Sun Jan 03, 2010 5:45 pm

Re: Is it normal for the Hints not to reappear? wxTextCtrl

Post by PB » Mon May 04, 2020 3:07 pm

So, is what you do any different than running into limitations described in the docs?
https://docs.wxwidgets.org/trunk/classw ... be83f1bed4

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4058
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Is it normal for the Hints not to reappear? wxTextCtrl

Post by ONEEYEMAN » Mon May 04, 2020 3:08 pm

Hi,
Try to call SetHint()

Thank you.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4058
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Is it normal for the Hints not to reappear? wxTextCtrl

Post by ONEEYEMAN » Mon May 04, 2020 3:18 pm

Hi,
@PB
It says that those limitations are for generic implementations

@OP:
Sets a hint shown in an empty unfocused text control.
So the answer is "NO". Control shuoldn't have a focus in order to display the hint.

Thank you.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2387
Joined: Sun Jan 03, 2010 5:45 pm

Re: Is it normal for the Hints not to reappear? wxTextCtrl

Post by PB » Mon May 04, 2020 3:40 pm

ONEEYEMAN wrote:
Mon May 04, 2020 3:18 pm
Hi,
@PB
It says that those limitations are for generic implementations
I know that but I did not know that the OP was not using generic implementation (such as on GTK2).
ONEEYEMAN wrote:
Mon May 04, 2020 3:18 pm
Sets a hint shown in an empty unfocused text control.
So the answer is "NO". Control shuoldn't have a focus in order to display the hint.
Actually, on Win10 the hint is still displayed in the focused control and disappears only when I type something and reappears when I delete all the text. Can be seen e.g. here

Code: Select all

#include <wx/wx.h>

class MyDialog : public wxDialog
{
public:
    MyDialog(): wxDialog(nullptr, wxID_ANY, "Test")
    {
        wxFlexGridSizer* mainSizer = new wxFlexGridSizer(2);
        
        for ( size_t i = 0; i < 4; ++i )
        {
            wxTextCtrl* textCtrl= new wxTextCtrl(this, wxID_ANY);
            textCtrl->SetHint(wxString::Format("wxTextCtrl #%zu", i + 1));
            mainSizer->Add(textCtrl, wxSizerFlags().Proportion(1).Expand().Border());
            mainSizer->Add(new wxButton(this, wxID_ANY, "Clear"), wxSizerFlags().Border());
        }
        
        Bind(wxEVT_BUTTON, &MyDialog::OnClear, this);

        SetSizerAndFit(mainSizer);
    }
private:
    void OnClear(wxCommandEvent& evt)
    {
        wxWindow* evtSource = dynamic_cast<wxWindow*>(evt.GetEventObject());
        wxTextCtrl* toClear = dynamic_cast<wxTextCtrl*>(evtSource->GetPrevSibling());

        if ( toClear )
            toClear->Clear();
    }
};

class MyApp : public wxApp
{
public:
    bool OnInit() override
    {        
        MyDialog().ShowModal();
        return false;
    }
}; wxIMPLEMENT_APP(MyApp);

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4058
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Is it normal for the Hints not to reappear? wxTextCtrl

Post by ONEEYEMAN » Mon May 04, 2020 4:01 pm

@PB,
Then I think the docs needs to be updated.

Thank you.

Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Is it normal for the Hints not to reappear? wxTextCtrl

Post by Nick » Tue May 05, 2020 1:30 am

PB wrote:
Mon May 04, 2020 3:40 pm
Actually, on Win10 the hint is still displayed in the focused control and disappears only when I type something and reappears when I delete all the text. Can be seen e.g. here
Interestingly for me, your example has the same effect that I reported earlier. If I write, and use the clear button, it erases TextCtrl but the tip is not shown! It is only displayed if I enter TextCtrl and exit it again. Or of course if I write inside of it, and inside of it I delete the text myself and get out of it!

I need the clear button to show the tip!

I use Linux, Slackware64-Current

Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Is it normal for the Hints not to reappear? wxTextCtrl

Post by Nick » Tue May 05, 2020 1:40 am

ONEEYEMAN wrote:
Mon May 04, 2020 3:08 pm
Hi,
Try to call SetHint()

Thank you.
Yeah, that's the way I found to solve it, creating the hint again. I even did a function with all the TextCtrl hints in one place only!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2387
Joined: Sun Jan 03, 2010 5:45 pm

Re: Is it normal for the Hints not to reappear? wxTextCtrl

Post by PB » Tue May 05, 2020 11:58 am

I can see differences even between Win7 and Win10.

Win7 (probably the same as observed by Nick):
1. The hint is shown only when the control does not have focus.
2. If I clear the control programmatically, the hint is not shown but appears if the control gets and loses focus.

Win10
1. The hint is always shown, regardless of focus.
2. If I clear the control programmatically, the hint appears.

Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Is it normal for the Hints not to reappear? wxTextCtrl

Post by Nick » Wed May 06, 2020 3:07 pm

Possible BUG?

I noticed that if I have a TextCtrl with the blue Text or any other color.
If by any chance I send him a text with the same text that exists configured in Hint, the text turns grey and not blue

I understood that because I send texts to TextCtrl from a Struct. And whenever the text from Struct is the same as Hint, TextCtrl keeps the gray color of Hint texts. Instead of using the pre-configured blue color. Do you realize that yet?
The Color only returns to normal blue, if I in this same field modify the text, or if I have any event that rewrites the text

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4058
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Is it normal for the Hints not to reappear? wxTextCtrl

Post by ONEEYEMAN » Wed May 06, 2020 3:32 pm

Hi,
It's not a bug.
It means that the native control behaviiour changed in Windows.

Unless of course you can reproduce the Win10 behaviour in the native Win32 application in Win7. Or vice versa.

Thank you.

Post Reply