其实就是改写了一个函数:mouseReleaseEvent,当在QLabel放开鼠标的时,就发射点击信号。
[cpp] view plaincopy
- #ifndef CLICKEDLABEL_H_
- #define CLICKEDLABEL_H_
- #include <QLabel>
- #include <QWidget>
- class ClickedLabel : public QLabel
- {
- Q_OBJECT
- signals:
- void Clicked(ClickedLabel* clicked);
- public:
- ClickedLabel(QWidget *parent=0): QLabel(parent),m_str("")
- {
- setText(m_str);
- };
- ~ClickedLabel() {};
- protected:
- void mouseReleaseEvent( QMouseEvent* );
- private:
- QString m_str;
- };
- #endif /* CLICKEDLABEL_H_ */
[cpp] view plaincopy
- #include "ClickedLabel.h"
- void ClickedLabel::mouseReleaseEvent(QMouseEvent *evt)
- {
- emit Clicked(this);
- }
参考:http://blog.csdn.net/tingsking18/article/details/4071619
时间: 2024-09-30 06:12:14