I've got a label with a mnemonic that precedes a custom widget - just a compound widget that derives from wxPanel, nothing too fancy. See below picture.
The problem is, I can't seem to get the mnemonic to work with that.
What I naively expect is for the custom widget to gain focus, but it doesn't seem to be the case.
What is the mechanism behind the mnemonics, then? How should a custom widget be made to work with them?
Mnemonics and custom widgets
Re: Mnemonics and custom widgets
Hi,
As you were told on SO - can you produce the SSCE so that it can be tested?
Also - what version of wxWidgets you are using and what port?
What OS/version you are testing this on?
Which compiler did you use to build the application and how did you configure the library?
And last but not least - what do you expect to happen?
Which sub-control should get focused?
Thank you.
As you were told on SO - can you produce the SSCE so that it can be tested?
Also - what version of wxWidgets you are using and what port?
What OS/version you are testing this on?
Which compiler did you use to build the application and how did you configure the library?
And last but not least - what do you expect to happen?
Which sub-control should get focused?
Thank you.
Re: Mnemonics and custom widgets
Hello,
Thanks for the reply. Didn't think it'd be necessary to post any code for my question, but here follows a minimal example of what I am talking about. It's a diff against the minimal.cpp sample program, found in the v3.0.5 branch of the repository.
Tested on Linux, with GTK3. Configure options:
Diff against minimal.cpp:
What I expect is to be able to press ALT+e and have the first wxTextCtrl focused, but instead the second one gets the focus. If I remove the second one from the code, I get the following line on the console:
Thanks.
Thanks for the reply. Didn't think it'd be necessary to post any code for my question, but here follows a minimal example of what I am talking about. It's a diff against the minimal.cpp sample program, found in the v3.0.5 branch of the repository.
Tested on Linux, with GTK3. Configure options:
Code: Select all
--enable-shared --disable-static --enable-unicode --enable-printfposparam --enable-debug --with-gtk=3
Code: Select all
diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 135595c9fb..0507952522 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -172,6 +172,24 @@ MyFrame::MyFrame(const wxString& title)
CreateStatusBar(2);
SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR
+
+ wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+
+ wxStaticText *label = new wxStaticText(this, wxID_ANY, wxS("T&est"));
+ wxPanel *panel = new wxPanel(this); {
+ wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+ wxTextCtrl *text = new wxTextCtrl(panel, wxID_ANY);
+ sizer->Add(text, wxSizerFlags(0).Expand());
+ panel->SetSizerAndFit(sizer);
+ }
+
+ wxTextCtrl *text2 = new wxTextCtrl(this, wxID_ANY);
+
+ sizer->Add(label, wxSizerFlags(0).Expand());
+ sizer->Add(panel, wxSizerFlags(0).Expand());
+ sizer->Add(text2, wxSizerFlags(0).Expand());
+
+ SetSizerAndFit(sizer);
}
Code: Select all
(minimal:2409662): Gtk-WARNING **: 01:58:45.676: Couldn't find a target for a mnemonic activation.
Re: Mnemonics and custom widgets
Hi,
OK, so you are working under Linux, right?
What is your version of GTK?
Did you build wxWidgets yourself or installed it from the repository?
If you build it - how? What is you exact configure line?
Thank you.
OK, so you are working under Linux, right?
What is your version of GTK?
Did you build wxWidgets yourself or installed it from the repository?
If you build it - how? What is you exact configure line?
Thank you.
Re: Mnemonics and custom widgets
Yes, as I wrote in the previous post, the code is being run under Linux, with the GTK3 target. The code is being linked against a locally built set of wx libraries, from the official v3.0.5 branch.
I've tested the same code on Windows as well, and I had a different set of issues. Namely, it seemed I couldn't switch focus between widgets with TAB at all, and the "OS bell" would ring any time I tried. Then I tried to use a wxPanel as root of all the other widgets, rather than putting them within the surrounding frame directly, and then the program started working as expected, but only on Windows. On Linux it still sports the same issue as before.
So the problem seems to be GTK-related? Gonna try building a GTK2 version of the libraries to see if that makes any difference.
Below, the updated code.
I've tested the same code on Windows as well, and I had a different set of issues. Namely, it seemed I couldn't switch focus between widgets with TAB at all, and the "OS bell" would ring any time I tried. Then I tried to use a wxPanel as root of all the other widgets, rather than putting them within the surrounding frame directly, and then the program started working as expected, but only on Windows. On Linux it still sports the same issue as before.
So the problem seems to be GTK-related? Gonna try building a GTK2 version of the libraries to see if that makes any difference.
Below, the updated code.
Code: Select all
diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 135595c9fb..89bc1dbea6 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -172,6 +172,26 @@ MyFrame::MyFrame(const wxString& title)
CreateStatusBar(2);
SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR
+
+ wxPanel *root = new wxPanel(this); {
+ wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+
+ wxStaticText *label = new wxStaticText(root, wxID_ANY, wxS("T&est"));
+ wxPanel *panel = new wxPanel(root); {
+ wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+ wxTextCtrl *text = new wxTextCtrl(panel, wxID_ANY);
+ sizer->Add(text, wxSizerFlags(0).Expand());
+ panel->SetSizerAndFit(sizer);
+ }
+
+ wxTextCtrl *text2 = new wxTextCtrl(root, wxID_ANY);
+
+ sizer->Add(label, wxSizerFlags(0).Expand());
+ sizer->Add(panel, wxSizerFlags(0).Expand());
+ sizer->Add(text2, wxSizerFlags(0).Expand());
+
+ root->SetSizerAndFit(sizer);
+ }
}
Re: Mnemonics and custom widgets
Hi,
What is an exact GTK version used?
And how did you configure the library? Please post exact configure line.
Thank you.
What is an exact GTK version used?
And how did you configure the library? Please post exact configure line.
Thank you.
Re: Mnemonics and custom widgets
I'm using the Ubuntu-provided binaries for the GTK libraries, I didn't compile them myself.
Code: Select all
$ LANG=C dpkg -l libgtk-3-0:amd64
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-================-================-============-====================================
ii libgtk-3-0:amd64 3.24.20-0ubuntu1 amd64 GTK graphical user interface library
Re: Mnemonics and custom widgets
Just tested the same minimal.cpp mods with the GTK2 target, and the result is exactly the same as with the GTK3 target.