16,215
社区成员
发帖
与我相关
我的任务
分享
connect(timer,SIGNAL(timeout()),this,SLOT(mouseClicked()));
//***单击事件启动定时器
void Mylabel::mousePressEvent(QMouseEvent *)
{
timer->start(50);
}
//***定义的单击事件槽函数,定时器超时,关闭定时器执行单击事件
void Mylabel::mouseClicked()
{
timer->stop();
emit sendLabelNum(labelNum);
}
//***定时内双击,执行双击事件
void Mylabel::mouseDoubleClickEvent(QMouseEvent *)
{
timer->stop();
emit sendMemoShow(labelNum);
}
这样写就差不多了Mylabel::Mylabel(int num)
{
labelNum = num;
setFixedSize(63,50);
timer =new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(mouseClicked()));
}
//***
void Mylabel::mouseClicked()
{
//根据当前label的样式来决定发什么信号
QString style = this->styleSheet();
if(EMPTY_LABELS_HEAD == style)
{
timer->stop();
emit lastMonth();
}
else if(EMPTY_LABELS_END == style)
{
timer->stop();
emit nextMonth();
}
else
{
timer->stop();
emit sendLabelNum(labelNum);
}
}
//***
void Mylabel::mousePressEvent(QMouseEvent *)
{
timer->start(50);
}
//***
void Mylabel::mouseDoubleClickEvent(QMouseEvent *)
{
QString style = this->styleSheet();
//防止空白格子误操作
if((EMPTY_LABELS_HEAD == style) || (EMPTY_LABELS_END == style))
{
timer->stop();
}
else
{
timer->stop();
emit sendMemoShow(labelNum);
}
}
void QWidget::mouseDoubleClickEvent ( QMouseEvent * event )
{
//do something
emit yourSignal();
}