Label position in layout breaks after trying to resize the window after using QPropertyAnimation - pyqt5

I have the following problem: I'm trying to animate a QLabel, more specifically to make it fadeIn using QPropertyAnimation. It animates successfully, but when I'm trying to resize the window, the label breaks out of the layout that's in, making it overlap with the other items.
The code:
self.label = QtWidgets.QLabel(self.frame)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
self.label.setStyleSheet("color: #fc8102;\n"
"font-weight: bold;\n"
"font-size: 18px;")
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.opacity_effect = QtWidgets.QGraphicsOpacityEffect(self.label)
self.opacity_effect.setOpacity(0)
self.label.setGraphicsEffect(self.opacity_effect)
self.anim = QtCore.QPropertyAnimation(self.opacity_effect, b'opacity')
self.anim.setDuration(800)
self.anim.setStartValue(0)
self.anim.setEndValue(1)
self.anim.start()
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.verticalLayout.addWidget(self.label)
Image with what's happening:
Image with how it's supposed to look:
Thanks in advance.

Related

PyQt5 - Get the pixel color inside a QWidget

I made a QWidget and inside I made some other items like QLabels which display images.
Consider what is inside that parent Widget I was trying to get the color where I would click.
Searching I found this thread but it is a bit old and I am not able to translate it to Python.
thread:
https://www.qtcentre.org/threads/49693-How-to-get-color-of-pixel-or-point
code:
QPixmap qPix = QPixmap::grabWidget(ui->myWidget);
QImage image(qPix.toImage());
QColor color(image.pixel(0, 1));
How would this translate this to PyQt5 if it is the correct answer?
QPixmap.grabWidget() is considered obsolete, and you should use QWidget.grab() instead.
pixmap = self.someWidget.grab()
img = pixmap.toImage()
color = img.pixelColor(0, 1)

How to change the icon for the matplotlib 'configure subplot' window?

I found that matplotlib's NavigationToolbar2Tk 'configure plot' window is being pulled from widgets.py
for ref: https://matplotlib.org/2.0.2/mpl_examples/pylab_examples/subplot_toolbar_01.pdf
The title for this window is Click on slider to adjust subplot param
Please advice me how to change its icon from default tkinter icon.
self.axleft = toolfig.add_subplot(711)
self.axleft.set_title('Click on slider to adjust subplot param')
self.icon = self.resource_path('icon.ico')
self.axleft.icon_bitmap = ImageTk.PhotoImage(Image.open(self.icon))
self.axleft.wm_iconbitmap(self.icon)
self.axleft.set_navigate(False)
I changed the above code starting in line 1115 in widgets.py. Here self.resource_path is a method I created to find the icon's path.
But getting error as subplots don't have the method wm_icon_bitmap
As #ImportanceOfBeingErnest pointed out.. I had to modify the configure_subplots method in _backend_tk.py. Used the wm_icon_bitmap method for the Toplevel widget.
def configure_subplots(self):
toolfig = Figure(figsize=(6,3))
window = Tk.Toplevel()
icon = self.resource_path('icon.ico')
window.icon_bitmap = ImageTk.PhotoImage(Image.open(icon))
window.wm_iconbitmap(icon)
canvas = type(self.canvas)(toolfig, master=window)
toolfig.subplots_adjust(top=0.9)
canvas.tool = SubplotTool(self.canvas.figure, toolfig)
canvas.draw()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
window.grab_set()

Kivy ScrollView, unable to scroll , scroll bar not shown

ScrollView:
size_hint_x:None
size_hint_y:None
background_color:[.2,.4,.4,1]
pos_hint:{'center_x':.97,'center_y':.55}
size_hint:.45,.5
GridLayout:
id:selecteditem
height: self.minimum_height
bar_width:3
cols:1
padding:1
spacing:3
size_hint:.45, .5
this is the .kv file code.
for i in range(100):
btn = Button(text=str(i), size=(250, 30),
size_hint=(None, None))
self.othroot.ids.selecteditem.add_widget(btn)
this is the code that i used as sample to create a 100 list of button.
Thank you in advance if anyone can help me on this.
This is the image regarding the issue

Repeatbehavior does not make animation end properly

I have a coloranimation in a UWP application to animate the background of a TextBox:
animation = new ColorAnimation();
animation.Duration = TimeSpan.FromMilliseconds(600);
animation.From = Colors.White;
animation.To = Color.FromArgb(255, 40, 40, 40);
animation.RepeatBehavior = new RepeatBehavior(2);
flashStoryBoard = new Storyboard();
flashStoryBoard.Children.Add(animation);
Storyboard.SetTarget(animation, MyBox);
Storyboard.SetTargetProperty(animation, "(Panel.Background).(SolidColorBrush.Color)");
When I run the animation above, the animation ends in the TextBox having a white background color instead of the expected default (which is the dark 40, 40 ,40 color..). When I remove the repeatbehavior the animation runs just fine but of course only once. There are no easing functions applied. When I set the fillbehavior to stop, I get a flickering effect at the end of the animation.
Any ideas?
When I run the animation above, the animation ends in the TextBox having a white background color instead of the expected default (which is the dark 40, 40 ,40 color..).
I'm not able to reproduce this problem, by my side it ends with the color "FF404040". Maybe you can create a new blank project and try your posted code again. Or you can share your sample with us.
When I set the fillbehavior to stop, I get a flickering effect at the end of the animation.
I think you are trying to make the TextBox's background changed from white to dark gray twice when the TextBox is loaded, but when set RepeatBehavior equals or over two times, it will flicker one more time very quickly in the end.
I found a workaround for this scenario, it makes the animation ending with the color "FF404040" and will not flicker in the end:
Storyboard flashStoryBoard = new Storyboard();
ColorAnimation animation = new ColorAnimation();
animation.Duration = TimeSpan.FromMilliseconds(600);
animation.To = Colors.White;
animation.From = Color.FromArgb(255, 40, 40, 40);
animation.RepeatBehavior = new RepeatBehavior(2);
animation.AutoReverse = true;
flashStoryBoard.Children.Add(animation);
Storyboard.SetTarget(animation, MyBox);
Storyboard.SetTargetProperty(animation, "(Panel.Background).(SolidColorBrush.Color)");
flashStoryBoard.Begin();
As you can see in my code, I swap the animation.To and the animation.From, and set the AutoReverse property to true. Since your animation's Duration is only 0.6s, I think this method will not effect the user experience and can solve the flickering problem.

DoubleAnimation of Width does not shrink

I am doing DoubleAnimation of the Width property of a Canvas. I want to shrink the canvas to 1/5 th of the size.
var widthAnimation = new DoubleAnimation();
widthAnimation.Duration = new TimeSpan(0,0,1);
StoryBoard.SetTarget(widthAnimation, Canvas1);
StoryBoard.SetTargetProperty(widthAnimation, new PropertyPath("Width"));
widthAnimation.From = Canvas1.Width;
widthAnimation.To = Canvas1.Width * .2;
StoryBoard stb = new StoryBoard();
stb.Children.Add(widthAnimation);
stb.Begin();
Somehow, the above animation does not shrink the size to 1/5th. Instead, it enlarges the canvas. Any clues why the animation is doing something funny?
The canvas was wrapped in a viewbox. The Viewbox size was fixed, while the canvas within it shrinked. The text expanded. Not sure why. But, I fixed the problem by applying the animation to the Viewbox rather than the Canvas. And it works all fine now.