資源簡介
可以讓QLabel實現點擊效果,實現點擊后出現線條和顏色變化
代碼片段和文件信息
#include?“label.h“
#include?
#include?
#include?
#include?
label::label(QString?strQWidget?*parent)?:
????QLabel(parent)
{
????QPalette?palette;
????palette.setColor(QPalette::WindowTextQColor(50255255));
????this->setText(str);
????this->setPalette(palette);
????setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
??//??this->setstyleSheet(“background-color:blue“);
????this->setCursor(Qt::PointingHandCursor);
????count?=?0;
????press?=?false;
????over?=?false;
????connect(thisSIGNAL(clicked())thisSLOT(change_color()));
}
void?label::mousePressEvent(QMouseEvent?*event)
{
????//如果單擊了就觸發clicked信號
????if?(event->button()?==?Qt::LeftButton)
????{
????????//觸發clicked信號
????????count++;
????????press?=?true;
??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-08-23?17:11??label_clicked\
?????文件????????1684??2013-08-23?16:03??label_clicked\label.cpp
?????文件?????????638??2013-08-23?16:02??label_clicked\label.h
?????文件?????????418??2013-08-22?23:37??label_clicked\label_clicked.pro
?????文件???????17714??2013-08-23?09:07??label_clicked\label_clicked.pro.user
?????文件???????17738??2013-08-23?00:45??label_clicked\label_clicked.pro.user.fbc0276
?????文件?????????187??2013-08-22?23:20??label_clicked\main.cpp
?????文件?????????850??2013-08-23?16:33??label_clicked\mainwindow.cpp
?????文件?????????387??2013-08-23?16:25??label_clicked\mainwindow.h
?????文件?????????654??2013-08-22?23:20??label_clicked\mainwindow.ui
評論
共有 條評論