Home » U++ Library support » LineEdit, EditFields, DocEdit » How to use LineEdit's default "Key" handler? no subclass (i want to use LineEdit's default Key(dword key, int count) handler without need to create a subclass)
How to use LineEdit's default "Key" handler? no subclass [message #59099] |
Wed, 02 November 2022 10:17  |
wakhshti
Messages: 2 Registered: November 2022
|
Junior Member |
|
|
how to use LineEdit, EditString, EditField default Key(press) handler?
there's many examples on how to use "Key(dword key, int count)" with subclass.
but how to use default Key press without sublassing?
(.h file)
class MainWindow : public WithmainLayout<TopWindow> {
public:
MainWindow();
LineEdit txtSearch;
private:
};
(.cpp file)
#include "MainWindow.h"
MainWindow::MainWindow()
{
CtrlLayout(*this, "MainWindow");
// txtSearch Key(dword key, int count) handler :
txtSearch.Key = ??
}
[Updated on: Wed, 02 November 2022 10:20] Report message to a moderator
|
|
|
Re: How to use LineEdit's default "Key" handler? no subclass [message #59112 is a reply to message #59099] |
Fri, 04 November 2022 02:04   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Hi Wakhshti,
I don't think these widgets support key event handler, so you will have to subclass them. However you can provide one in your subclass, then all objects of your subclass will be able to supply individual customised key event handler.
Here is a quick example. Let me know if you need further explanations.
Regards,
Lance
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
// subclass EditString, and define an Event(actually a Gate)
class MyEditString : public EditString
{
bool Key(dword key, int rep)override
{
return (WhenKey && WhenKey(key, rep) ) ||
this->EditString::Key(key, rep);
}
public:
Gate<dword, int> WhenKey;
};
// actually use it
class MyWin : public TopWindow
{
public:
MyWin()
{
// the event handler will make the edit throw away key 'A';
e.WhenKey = [=, this](dword key, int){
return key == 'a' || key == 'A';
};
// the event handler will make the edit filter out digit key
f.WhenKey = [=, this](dword key, int){
return key >='0' && key <='9';
};
Add(e.TopPosZ(5).LeftPosZ(5));
Add(f.TopPosZ(35).LeftPosZ(5));
}
MyEditString e, f;
};
GUI_APP_MAIN
{
MyWin().Run();
}
|
|
|
|
Goto Forum:
Current Time: Sat May 10 13:48:14 CEST 2025
Total time taken to generate the page: 0.00474 seconds
|