Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
wakhshti is currently offline  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 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 534
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();
}
Re: How to use LineEdit's default "Key" handler? no subclass [message #59117 is a reply to message #59099] Sat, 05 November 2022 11:09 Go to previous message
peterh is currently offline  peterh
Messages: 108
Registered: November 2018
Location: Germany
Experienced Member
BTW, if your reason not to use a subclass is the GUI designer, then see here:
https:// www.ultimatepp.org/forums/index.php?t=msg&th=10854&g oto=58793&#msg_58793
Previous Topic: LineEdit get Key press no subclass
Next Topic: Rescale image without filter
Goto Forum:
  


Current Time: Sun Jun 16 20:43:46 CEST 2024

Total time taken to generate the page: 0.01455 seconds