gtkmm changing toggle button state without invoking signal - radio-button

I'm trying to make multiple Gtk::ToggleButton's to act as Gtk::RadioButton's. When one of the buttons is pressed that other switch off.
It would be as simple as creating a switch statement if Gtk::ToggleButton didn't handle switching (pressed or not pressed) on its own.
So, I'm planning to handle it's switching as regular button with calling signal_clicked().connect() which calls for function set_active(true/false) which makes button look pressed or not pressed.
Here is example of what I'm trying to do:
Event calls when button is clicked:
//enum {infoState, artState, editState, userState, exitState}; is initialised in header
artButt.signal_clicked().connect(sigc::bind<short int>(sigc::mem_fun(*this, &fooclass::toggleButton), artButt));
editButt.signal_clicked().connect(sigc::bind<short int>(sigc::mem_fun(*this, &fooclass::toggleButton), editButt));
Toggling button:
void fooClass::toggleButton()
{
//oldState and enum {infoState, artState, editState, userState, exitState}; are initialised in header
if(oldState != newState)
{
//disable old togglebutton
switch (oldState)
{
case infoState:
infoButt.set_active(false);
break;
case artState:
artButt.set_active(false);
break;
case editState:
editButt.set_active(false);
break;
case userState:
userButt.set_active(false);
break;
}
//enable new one
switch (newState)
{
case infoState:
userButt.set_active(false);
break;
case artState:
artButt.set_active(true);
break;
case editState:
editButt.set_active(true);
break;
case userState:
userButt.set_active(true);
break;
}
oldState = newState;
}
}

Just useGtk::RadioButton directly. With the draw-indicator property you can make them look like regular toggle buttons.

Ok, so here is my workaround. There is probably better way, so please if you know any post it here:
Firstly use Gtk::Button instead of Gtk::ToggleButton .
Secondly instead of set_active() use set_state_flags(). Gtk::STATE_FLAG_CHECKED when you want it to be enabled and GTK::STATE_FLAGS_NORMAL when you want it to be disabled.
So, this is how code should look like:
void Window::changeState()
{
if(oldState != state)
{
//delete old state
switch (oldState)
{
case infoState:
infoButt.set_state_flags(Gtk::STATE_FLAG_NORMAL);
break;
case artState:
artButt.set_state_flags(Gtk::STATE_FLAG_NORMAL);
break;
case editState:
editButt.set_state_flags(Gtk::STATE_FLAG_NORMAL);
break;
case userState:
userButt.set_state_flags(Gtk::STATE_FLAG_NORMAL);
break;
}
//move to new state
switch (state)
{
case infoState:
infoButt.set_state_flags(Gtk::STATE_FLAG_CHECKED);
break;
case artState:
artButt.set_state_flags(Gtk::STATE_FLAG_CHECKED);
break;
case editState:
head.editButt.set_state_flags(Gtk::STATE_FLAG_CHECKED);
break;
case userState:
userButt.set_state_flags(Gtk::STATE_FLAG_CHECKED);
break;
case exitState:
close();
break;
}
show_all_children();
oldState = state;
}
}

Related

How can I encode strings in Flutter Application?

I have a class called ُCreatorUrl in flutter. In this class and other classes, strings including the names of database tables are specified.
How to protect data and strings in the flutter?
Is this a common way of programming?
Please help me.thank's
class CreatorUrl {
static Future<String> createLinkRequest(Map body,{int page:20}) async {
String blankUrl = 'http:mysite/myApi/api.php?x={"ApiKey":"SAZUChQJh8D7WRyJTc4BERedWd"';
switch (body['MOD']) {
case 'select':
blankUrl=blankUrl+',"MOD":"select","table":"${body['table']}","what":"*","sql":"${body['sql']}","limit":"0,${page==null?200:page}"}';
break;
case 'insert':
blankUrl=blankUrl+',"MOD":"insert","table":"${body['table']}","insert":"${body['insert']}"}';
break;
case 'delete':
break;
case 'update':
blankUrl=blankUrl+',"MOD":"update","table":"${body['table']}","update":"${body['update']}","sql":"${body['sql']}"}';
break;
case 'count':
blankUrl=blankUrl+',"MOD":"count","table":"${body['table']}","sql":"${body['sql']}"}';
break;
case 'sms':
blankUrl=blankUrl+',"MOD":"sms","mob":"${body['mob']}","text":"${body['text']}"}';
print("Im here s");
break;
}
return blankUrl;
}
}
This may be useful about your problem
Also read this document

How to Remove this Arrow or Image From IOS Listview in Xamarin forms

when i write a listview in xamarin forms this icon is auto added to IOS and this is not present in Android
i tried removing this using custom renderer by rendering viewrenderer but this this view renderer never gets call
here is the code which i used for custom renderering
[assembly: ExportRenderer(typeof(ViewCell),
typeof(StandardViewCellRenderer))]
namespace Sample.iOS.Renderers.RevisedRenderer
{
public class StandardViewCellRenderer : ViewCellRenderer
{
public override UIKit.UITableViewCell GetCell(Cell item,
UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
{
var cell = base.GetCell(item, reusableCell, tv);
switch (item.StyleId)
{
case "none":
cell.Accessory = UIKit.UITableViewCellAccessory.None;
break;
case "checkmark":
cell.Accessory = UIKit.UITableViewCellAccessory.Checkmark;
break;
case "detail-button":
cell.Accessory =
UIKit.UITableViewCellAccessory.DetailButton;
break;
case "detail-disclosure-button":
cell.Accessory =
UIKit.UITableViewCellAccessory.DetailDisclosureButton;
break;
case "disclosure":
default:
cell.Accessory =
UIKit.UITableViewCellAccessory.DisclosureIndicator;
break;
}
return cell;
}
}
}
let me know what need to be modified or add to make it work
remove your switch, and leave the code like this:
var cell = base.GetCell (item, reusableCell, tv);
cell .Accessory = UITableViewCellAccessory.DisclosureIndicator;
You can get more details at:
https://forums.xamarin.com/discussion/88286/xamarin-viewcell-how-to-turn-off-right-arrow-meant-for-touch-action
Cause:
i tried removing this using custom renderer by rendering viewrenderer
but this this view renderer never gets call
The view renderer did get call in your project while the code inside Switch statement never executed, because item.StyleId is always null. You can add a breakpoint to check it.
Solution:
If you want to remove the arrow, just set cell.Accessory = UIKit.UITableViewCellAccessory.None; will work.
class StandardViewCellRenderer : ViewCellRenderer
{
public override UIKit.UITableViewCell GetCell(Cell item,
UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
{
var cell = base.GetCell(item, reusableCell, tv);
Console.WriteLine(item.StyleId);
cell.Accessory = UIKit.UITableViewCellAccessory.None;
// switch (item.StyleId)
// {
// case "none":
// cell.Accessory = UIKit.UITableViewCellAccessory.None;
// break;
// case "checkmark":
// cell.Accessory = UIKit.UITableViewCellAccessory.Checkmark;
// break;
// case "detail-button":
// cell.Accessory =
// UIKit.UITableViewCellAccessory.DetailButton;
// break;
// case "detail-disclosure-button":
// cell.Accessory =
//UIKit.UITableViewCellAccessory.DetailDisclosureButton;
// break;
// case "disclosure":
// default:
// cell.Accessory =
// UIKit.UITableViewCellAccessory.DisclosureIndicator;
// break;
// }
return cell;
}
}
If you want to show cells with different cell.Accessory style, you can create a custom property instead of using StyleId.
I also uploaded a demo here.

Selective keyPressEvent, filter for its sender QLineEdit

I've created a QWidget, which contains three QLineEdits. Then I added a overwrote the keyPressEvent so that this lineEdit_3 reacts on key press. Working good.
void MySuperWidget::keyPressEvent(QKeyEvent* keyEv)
{
switch (keyEv->key()) {
case Qt::Key_Up:
//.. stuff
break;
case Qt::Key_Down: {
//.. stuff
}
break;
default:
break;
}
}
BUT the first and second QLineEdit also react on keypress :(
I need somethng like this:
if (sender() != ui->lineEdit_3 ) {
keyEv->ignore();
}

How to make the start Snackbar message when you click on the menu?

How to make the start Snackbar message when you click on the menu?
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case (R.id.reset):
number1.setText(null);
number2.setText(null);
//Snackbar.make(findViewById(android.R.id.content) , "Text", Snackbar.LENGTH_SHORT).setAction("Action", null).show();
break;
case (R.id.quit):
finish();
break;
}
return super.onOptionsItemSelected(item);
}
It does not react.
You can use the main activity view to display the SnackBar :
Snackbar.make(this.findViewById(android.R.id.content),
"FooBar", Snackbar.LENGTH_LONG).setAction("Action", null).show();
When you click on menu item you can do like this:
Snackbar.make(getWindow().getDecorView(), .....);
Remember you MUST pass View object in order to show snackbar

Is it possible to disable split screen view from metro app (windows 8)?

I have a metro app that will behave funny when user uses the "split screen" windows 8 functionality (as in the following image: http://pureinfotech.com/wp-content/uploads/2012/03/metro-app-desktop-split-screen-windows-8.png).
Is there a way to programatically disable from inside of your app? I haven't found any so far, but I am posting this just in case anyone knows any better.
Thanks in advance!
No, you cannot.
I would recommend just navigating to a Splash Screen sort of thing.
Look what happens when you snap the Windows Store.
It is technically possible but probably it won't pass the app certification.
You can try using ApplicationView.TryUnsnap()
in the event handler for SizeChanged event of your Page:
In ctor put:
Window.Current.SizeChanged += OnSizeChanged;
And implement the handler method:
public void OnSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs args)
{
switch (Windows.UI.ViewManagement.ApplicationView.Value)
{
case Windows.UI.ViewManagement.ApplicationViewState.Filled:
VisualStateManager.GoToState(this, "Fill", false);
break;
case Windows.UI.ViewManagement.ApplicationViewState.FullScreenLandscape:
VisualStateManager.GoToState(this, "Full", false);
break;
case Windows.UI.ViewManagement.ApplicationViewState.Snapped:
VisualStateManager.GoToState(this, "Snapped", false);
break;
case Windows.UI.ViewManagement.ApplicationViewState.FullScreenPortrait:
VisualStateManager.GoToState(this, "Portrait", false);
break;
default:
break;
}
this.ShowCurrentViewState();
}
void ShowCurrentViewState()
{
ApplicationViewState currentState = Windows.UI.ViewManagement.ApplicationView.Value;
if (currentState == ApplicationViewState.Snapped)
{
ApplicationView.TryUnsnap() ;
}
}