实质:在点击标签的时候发射一个点击信号
1.设置一个类继承QLabel(重写鼠标点击事件,增加一个信号):
1 class: QClickLabel:public QLabel{ 2 Q_OBJECT 3 public: 4 QClickLabel(QWidget *parent); 5 ~QClickLabel(); 6 7 protected: 8 void mousePressEvent(QMouseEvent* event){
if(event->button() == Qt::LeftButton)
emit clicked();
} 9 10 signals: 11 void clicked(); 12 13 }
2.使用此标签(以在for循环中为例:)
for(int row=0; row<3; row++){ for(int column=0; column<4; column++){ QClickLabel *label = new QClickLabel(this); label->setCursor(Qt::PointingHandCursor); //设置光标的形象(手形象) connect(label,QClickLabel::clicked,[row,column](){ XXXX; }); } }
标签:功能,QClickLabel,标签,点击,clicked,event,row From: https://www.cnblogs.com/ylww/p/17537443.html