U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Proposal: add IsReadOnly() handling inside ButtonOption
Re: Proposal: add IsReadOnly() handling inside ButtonOption [message #26435 is a reply to message #26434] Sat, 01 May 2010 18:01 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1796
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Mindtraveller wrote on Sat, 01 May 2010 16:07

I've made a number of attempts to make "chosen" button option irresponsible to user clicks and failed. Digging into code revealed that there is no way to make it.

Hi Pavel!

There is a way Wink Maybe not as straightforward as your patch, but it works fine too. The trick is to check the value of ButtonOption in WhenAction callback and revert the action whenever user tries to "unclick" the button:
#include "CtrlLib/CtrlLib.h"
using namespace Upp;

struct App : TopWindow {
	typedef App CLASSNAME;
	Array<ButtonOption> btns;
	void Check(int n){
		if (~btns[n]==0) btns[n].Set(true);
		else for(int i = 0; i < btns.GetCount(); i++)
			if(i!=n) btns[i].Set(false);
	}
	App(){
		btns.Add().SetLabel("Click me! :-)").SetRect(10,10,200,50);
		btns.Add().SetLabel("No, click me! (-:").SetRect(10,70,200,50);
		for(int i = 0; i < btns.GetCount(); i++){
			btns[i]<<=THISBACK1(Check,i);
			Add(btns[i]);
		}
	}
};

GUI_APP_MAIN{
	App().Run();
}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: QTF with QtfRichObject as Button label causes crash
Next Topic: Moving child ctrl, runtime, by mouse and keyboard
Goto Forum:
  


Current Time: Sat Jun 20 21:24:55 GMT+2 2026

Total time taken to generate the page: 0.00452 seconds