我正在设置一个新的桌面小部件,使我的工作生活更轻松,并使用QPropertyAnimation使它更漂亮。淡入淡出的应用程序似乎不想工作,在典型的编码方式,它带来了我的进展停顿。你知道吗
我在一个个性化的类中实现QPropertyAnimation,以使我的生活更轻松,但由于它最初没有起作用,我将它带回类代码中,它仍然非常顽固。到目前为止我已经试过了。你知道吗
class widget(QWidget):
def init(self):
self.setSize(QSize(300, 300))
self.setWindowOpacity(1)
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.setAttribute(Qt.WA_TranslucentBackground)
def paintEvent(self, event):
s = self.size()
qp = QPainter()
qp.begin(self)
qp.setRenderHint(QPainter.Antialiasing, True)
qp.setBrush(QColor().fromRgb(2,106,194))
qp.setPen(QColor().fromRgb(2,106,194))
qp.drawRoundRect(QRect(0,0, 300, 300), 16, 8)
qp.end()
def show(self):
self.superShow()
a = QPropertyAnimation(self, "windowOpacity")
a.setDuration(500)
a.setStartValue(1)
a.setEndValue(0)
a.start()
def hide(self):
a = QPropertyAnimation(self, "windowOpacity")
a.setDuration(500)
a.setStartValue(0)
a.setEndValue(1)
a.finished.connect(self.superHide)
a.start()
def superShow(self):
super(widget, self).show()
def superHide(self):
super(widget, self).hide()
完全没有错误消息它只是在动画持续时间结束后隐藏和显示。不知道该去哪里找,也不知道该怎么做才能让它工作。我只写了3个月左右的代码。你知道吗
您的代码有许多错误,例如:
我将使用QGraphicsOpacityEffect代替直接更改不透明度,而不是使用show和close方法,我将使用showEvent、hideEvent和closeEvent方法。你知道吗
相关问题 更多 >
编程相关推荐