继承 QWidget 的类的 mousePressEvent 和 mouseReleaseEvent 没响应?
AHostList.h
class AHostList:public QWidget
{
Q_OBJECT
public:
AHostList(QString & path);
~AHostList();
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
};
AHostList.cpp:
AHostList::AHostList(QString &path)
{
this->setCursor(Qt::BlankCursor);
setWindowFlags(Qt::FramelessWindowHint);
m_mainWidget = new QListWidget(this);
char * pFirstText = "NAME SIZE TIME";
m_firstLabel = new QLabel(this);
m_firstLabel->setFont(QFont("Helvetica",14, QFont::Bold,0));
m_firstLabel->setStyleSheet("QLabel{background-color:blue}");
m_firstLabel->setText(pFirstText);
m_firstLabel->resize(800,35);
QDir picdir(path);
fileList = picdir.entryInfoList();
QFileInfo fileInfo;
QString fileText;
m_sumItem = 0;
m_itemCount = (int)fileList.count();
//从2开始是因为有 . ..
for(int i = 2; i < m_itemCount; i++){
fileInfo = fileList.at(i);
fileText += fileInfo.fileName();
fileText += " ";
fileText += QString::number(fileInfo.size());
fileText += "K ";
QString format("MM-dd hh:mm:ss");
//最后修改的时间
fileText += fileInfo.lastModified().toString(format);
pListWidgetItem[i-2] = new QListWidgetItem(fileText,m_mainWidget);
pListWidgetItem[i-2]->setSizeHint(QSize(800,40));