Enable Opposite - qt

Why won't this work?
void RatingWidget::mouseDoubleClickEvent(QMouseEvent * e)
{
this->setEnabled(!this->Enabled);
}
// I also tried...
void RatingWidget::mouseDoubleClickEvent(QMouseEvent * e)
{
if(this->isEnabled())
this->setEnabled(false);
else
this->setEnabled true;
}
It works the first time, but after that it remains disabled.

To quote the documentation..
An enabled widget handles keyboard and mouse events; a disabled widget
does not.
So once you disable it, you aren't going to get any more mouse events :)

Related

ChangeEvent blocks QMDISubWIndow

n my App I use a QMDIArea. In this I open now a subclassed MDIChild that has a master class. Inside the master class I set the virtual changeEvent of the subwindow. But if I use this event I cannot move the window in the QMDIArea anymore and the sub window is not create in maximized.
If I remove the Event from the class it works again well. Do I use the Event the wrong way?
MdiChildBase.h
private:
virtual void changeEvent(QEvent * e);
MdiChildBase.cpp
void MdiChildBase::changeEvent(QEvent * e) {
if(e->type() == QEvent::WindowStateChange && this->isActiveWindow()) {
// .. this is now the active window
qDebug("Iam active now");
}
QWidget::changeEvent(e);
}
Ok after reading the docs and try something around the solution for this question is:
void MdiChildBase::changeEvent(QEvent * e) {
QMdiSubWindow::changeEvent(e);
if(e->type() == QEvent::WindowStateChange && this->isActiveWindow()) {
// .. this is now the active window
qDebug("Iam active now");
}
}

How to disable back button When ActivityIndicator Is Running

I am using Xamrin.forms PLC Project,
So,I am trying to disable back button when Activity Indicator is Running then I will enable back button when Activity Indicator is finished.
this is My Code:
protected override void OnAppearing()
{
activityIndicator.IsRunning = true;
activityIndicator.IsVisible = true;
//I need to disable back button here
activityIndicator.IsRunning = false;
activityIndicator.IsVisible = false;
//I need to enable back button here
}
You can use the static NavigationPage.SetHasBackButton method (See here) to hide the back button of your page.
Furthermore you can override OnBackButtonPressed
protected override bool OnBackButtonPressed()
{
if(activityIndicator.IsRunning = true)
{
return true;
}
return false;
}
(see here) to prevent going back when the user presses the hardware back button.

Rearranging parent-child activation order in Caliburn Micro

During my override of OnActivate() in my view-model, I need to call GetView() in order to focus an element. When I do this after I have previously activated my view, it's fine. But when I call this the first activation, it fails.
I was able to get it to work by swapping a few lines in ConductorBaseWithActiveItem.ChangeActiveItem. The original is as follows:
protected virtual void ChangeActiveItem(T newItem, bool closePrevious) {
ScreenExtensions.TryDeactivate(activeItem, closePrevious);
newItem = EnsureItem(newItem);
if(IsActive)
ScreenExtensions.TryActivate(newItem);
activeItem = newItem;
NotifyOfPropertyChange("ActiveItem");
OnActivationProcessed(activeItem, true);
}
and with my changes:
protected virtual void ChangeActiveItem(T newItem, bool closePrevious) {
ScreenExtensions.TryDeactivate(activeItem, closePrevious);
newItem = EnsureItem(newItem);
activeItem = newItem;
NotifyOfPropertyChange("ActiveItem");
if (IsActive)
ScreenExtensions.TryActivate(newItem);
OnActivationProcessed(activeItem, true);
}
This seems to work. Notifying that "ActiveItem" changed triggers the code to load and cache the view. Then ScreenExtensions.TryActivate calls my OnActivate override.
Question: I haven't noticed any problems doing this, but I'm curious if anyone knows better than I do what repercussions this change could have?
Thanks!
One thing you could try is overriding Caliburn's OnViewAttached method and trying to focus it there. That being said, in MVVM, focus is more of a View concern, so if possible, that logic should be moved from the ViewModel to the View.
One way you may be able to solve this is by creating an attached behavior (you will need a reference to the Microsoft.Expression.Interactions assembly):
public class FocusWhenVisibleBehavior : Behavior<FrameworkElement>
{
protected override void OnAttached()
{
this.AssociatedObject.Loaded += this.Loaded;
this.AssociatedObject.IsVisibleChanged += this.VisibleChanged;
}
protected override void OnDetaching()
{
this.AssociatedObject.Loaded -= this.Loaded;
this.AssociatedObject.IsVisibleChanged -= this.VisibleChanged;
}
private void Loaded(object sender, RoutedEventArgs e)
{
this.TryFocus();
}
private void VisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
this.TryFocus();
}
private void TryFocus()
{
if (this.AssociatedObject.IsLoaded && this.AssociatedObject.IsVisible)
{
// Focus the control
this.AssociatedObject.Focus();
}
}
}
And that attaching that behavior to whatever control you want to focus:
<Button>
<i:Interaction.Behaviors>
<b:FocusWhenVisibleBehavior/>
</i:Interaction.Behaviors>
</Button>

How to detect if a window has been activated?

Focus events don't work because they're not sent if you activate your window by clicking on its non-client frame. Also, if you click the internal components of the window THEY will get the focus event, not your window, but the window will still be activated, even if it wasn't active or focused before.
The event you want is QEvent::WindowActivate. Override event() to process it:
bool YourWidget::event(QEvent *e)
{
if (e->type() == QEvent::WindowActivate) {
// window was activated
}
return QWidget::event(e);
}
Qt provides several virtual event handling functions you can use. Since the activation of a window changes its state, you want to handle some change events:
void MyWidget::changeEvent(QEvent * e) {
if(e->type() == QEvent::ActivationChange && this->isActiveWindow()) {
// .. this is now the active window
}
}
References
changeEvent
isActiveWindow

Buttons with state android

Good evening,
I ask myself the following head breaks:
I would like to create a Favorites button that has the two following states:
1st state: "Add to Favorites"
2nd state (on OnClick event): "Remove from favorites"
But I'd also be able to return to the 2nd state: "Add to Favorites" by a 2nd OnClick event ect..
Does anyone have a solution for it with a simple OnClickListener it seems impossible.
I finally solved my problem using a custom checkbox !!Is the best way to use favorite things because you can get the state of your drawable !!
like that :
favoris_button = (CheckBox) findViewById(R.id.star);
favoris_button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
favoris_button.setText("Supprimer des categories");
}
else
favoris_button.setText("Ajouter aux favoris");
}
});
Run this code inside your listener or wrap a function around it and pass it the boolean and call it when you need to. Startup, reset or whenever you want to change the state. If the button is clicked you need to flip the state.
private Boolean check;
favoris_button = (Button) findViewById(R.id.promotion_favoris);
favoris_button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if (check == true)
{
favoris_button.setBackgroundColor(R.drawable.btn_orange9);
favoris_button.setText("Supprimer des favoris");
}
else
{
favoris_button.setBackgroundColor(R.drawable.btn_red9);
favoris_button.setText("Ajouter aux favoris");
}
check ^= true;
}
});

Resources