我要征求你们的意见,因为我没什么主意了。我在做可点击标签。我已经完成了一些“ClickableLabel”类并处理了mouseover事件—它会更改标签边框,并在鼠标离开时返回到正常状态。你知道吗
现在我希望它在标签上有一个自定义的发光效果,但我希望它在点击后返回到正常状态,比如说0.5秒。你知道吗
我希望我的标签上有一个模仿按钮的图像。time.sleep
工作不太好,尤其是在垃圾邮件点击时,它会冻结应用程序主线程。你知道吗
希望我不是在重新发明方向盘,但据我所知,这是一条路要走。你知道吗
这是示例代码,请回答。你知道吗
from PySide2.QtWidgets import QLabel, QSizePolicy, QGraphicsDropShadowEffect
from PySide2.QtGui import QPixmap
from PySide2.QtCore import (Signal, QEvent, QObject, QRect)
class ClickableLabel(QLabel):
def __init__(self, pic_path, width, height, border_color, click_function):
super(ClickableLabel, self).__init__()
# Setting the picture path and setting pixmap to label
self.pic_path = pic_path
self.pixmap = QPixmap(self.pic_path)
self.setPixmap(self.pixmap)
# Set the size
self.setFixedSize(width, height)
# Enable tracking and assign function
self.setMouseTracking(True)
self.click_function = click_function
# Set default
if border_color is None:
self.border_color = 'lightblue'
else:
self.border_color = border_color
def mouseMoveEvent(self, event):
# event.pos().x(), event.pos().y()
self.setStyleSheet("border: 1px solid " + str(self.border_color) + ";")
def leaveEvent(self, event):
# event.pos().x(), event.pos().y()
self.setStyleSheet("border: None")
def mousePressEvent(self, event):
self.click_function()
effect = QGraphicsDropShadowEffect(self)
effect.setOffset(0, 0)
effect.setBlurRadius(20)
effect.setColor(self.border_color)
self.setGraphicsEffect(effect)
是的,这是可以实现的,因为您有:
您可以在测试类中模拟
hotelsServiceInt
,并返回模拟结果。在调用doSomeBusinessLogic
之前,只需返回一个模拟列表,就可以开始了。 您还需要更改@Mock
和@InjectMock
的变量类型,如下所示:现在,您应该能够获得所需的结果
相关问题 更多 >
编程相关推荐