SwiftUI fade-in on disappear - swiftui

I'm animating an overlay for one of my views and the expected animation is:
On appear:
Start out with opacity = 1
Animate to opacity = 0
As I undertand, this is fairly easy to do with a boolean state variable that gets set within an onAppear and a standard animation
Here's where things get tough
On disappear:
Start out with opacity = 0
Animate to opacity = 1
This isn't possible to do within a onDisappear because the state change won't get animated as the object is disappearing
I know people use .transition for similar animations, but .transition forces the opacity to animate to 0 on disappear and to 1 on appear.

Related

Selection color disappears if listRowBackground changed

If I change the row background color, then the default grey selection when I tap on the row disappears.
Is it possible to bring it back? Or do I have to add a custom overlay/manually change the color of the row when selected?
The code I used for changing the background color is the following: .listRowBackground(Color(.secondarySystemGroupedBackground))

Qt removing the frame?

Is there an efficient way of removing the frame and setting the background colour to transparent in Qt? Another thing I would like to make is to have the window being "moveable" too i.g. whenever I press and and hold the left mouse button I can move the window wherever I like.
Graphically to express the result I would like to achieve.
----------
Solution in order to make it "moveable": https://forum.qt.io/topic/34354/solved-frameless-window-dragging-issue/2
First you have to set the window flag (i do this in an overloaded QDialog::exec):
setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
(just add Qt::FramelessWindowHint to your window flags)
Then you add transparent background:
setAttribute(Qt::WA_TranslucentBackground);
...and make sure autoFillBackground is not set (uncheck in Designer if checked)
If you need to add a shadow, simply add a DropShadowEffect to the widget which creates the backgroud rounded rectangle:
auto dropShadow = new QGraphicsDropShadowEffect;
dropShadow->setOffset(0);
dropShadow->setBlurRadius(40);
dropShadow->setColor(QColor(0, 0, 0, 180));
ui.backgroundWidget->setGraphicsEffect(dropShadow);
The shadow is painted on the widget itself, so you need additional space around your background widget. I.e. if your BlurRadius is set to 40 you should set a 40 pixel margin:
layout()->setMargin(40);

How can I make a QTextEdit widget scroll from my program

I have a QTextEdit widget with a vertical scroll bar.
report_text = new QTextEdit();
report_text->setAcceptRichText(true);
report_text->setReadOnly(true);
report_text->setTextInteractionFlags(Qt::NoTextInteraction);
report_text->setAlignment(Qt::AlignTop);
report_text->setWordWrapMode(QTextOption::NoWrap);
report_text->setFrameStyle(QFrame::NoFrame);
report_text->setMinimumSize(600, 380);
report_text->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
This is Qt 4.8 embedded.
Now I need a method or an event I can send to the widget to make it it scroll up or down just as if the up or down buttons on the scroll bar had been pressed.
I tried the scroll() method, but I scrolls the whole widget, including the scroll bar.
I also tried sending a QWheelEvent, but nothing happens.
QWheelEvent ev(QPoint(), 10, 0, 0);
report_text->setFocus();
QApplication::sendEvent(report_text, &ev);
What am I missing?
It is probable that the delta you provided is just way too small.
From the documentation of QWheelEvent::delta():
Returns the distance that the wheel is rotated, in eighths of a
degree. A positive value indicates that the wheel was rotated forwards
away from the user; a negative value indicates that the wheel was
rotated backwards toward the user.
Most mouse types work in steps of 15 degrees, in which case the delta
value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
The text scrolling in Qt unit is the number of whole line. So if the widget computes that you want to scroll 0.9 lines, he might do nothing.
So try again with
QWheelEvent ev(QPoint(), 120, 0, 0);
Note: Nothing here apply to an event with control or shift modifier.
Here is what I found as a suitable solution:
The vertical scrollbar may be accessed using the QTextEdit::verticalScrollBar() method.
Scrollbars have a triggerAction() method to conveniently simulate user interaction with the buttons and the slider. The available actions are defined in QAbstractSlider.
So the resulting code is only a single line:
report_text->verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepAdd);
Interestingly, this works even when the scrollbar is hidden with
report_text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

Stringray Grid transparent background

In Stringray grid, there is the ability to use a transparent background which allows the background of the dialog to be shown through the grid.
In the documentation it states:
But be careful; you should disable scrolling or you have to redraw the grid each time it is scrolled (by overriding DoScroll).
I have a scrollable gird and override the DoScroll and make sure I call Redraw and also tried Invalidate, however the grid is still not completely erasing and redrawing.
I also tried using the old drawing method by setting m_bForceOldDrawing to TRUE.
How can I create a grid that has a transparent background that paint correctly after a scroll without leaving artifacts?
Yes you have to redraw the grid by overriding DoScroll because it is no longer using ScrollWindow to scroll contents because the background is transparent.
However you now have artifacts of the grid over your background.
This is because the background behind the grid is not getting redrawn.
Do you have clipchildren set for the parent?
Another potential problem is that the background is not being drawn because it doesn't realize it has been exposed.
Try calling the parent with the following.
Parent.Invalidate();
Parent.UpdateWindow();
before calling...
Invalidate();

How do I create a rotating cube effect in Qt?

I have a QGraphicsView and a slide show of QGraphicsScenes, at the moment when the user switches to the next slide I just change the Scene that the View is looking at and it changes instantly to reflect that.
What I would like to do it create some transition effects, such as the rotating cube or the slide in/out.
However looking at the QPropertyAnimation class it seems to be about moving an object not transitioning from one to another.
As in I would need a view for each scene and then transition between each view.
What other strategy could I employ?
Instead of changing the scene that the view sees, you could use property animations to slide graphic items in and out of the view from a single scene. That would give you the slide in/out transition without too much effort. The rotating cube effect would be trickier but I think a reasonable facsimile could be produced with property animations.
You could also simulate other effects by subclassing the view widget and adding some custom properties that you could animate and use to direct background or foreground painting.