What kind of errors do you get?
This compiles fine:
/***************************************************************************
* Copyright (C) 2004 by Witold Wysota *
* wysota@wysota.eu.org *
* *
***************************************************************************/
#ifndef WWCLASSES_H
#define WWCLASSES_H
#include <QLabel>
#include <QTimer>
#include <QPoint>
/**
* @class wwActiveLabel
* @brief Label with mouse click and mouse move support
*
*
*/
class wwActiveLabel
: public QLabel{
Q_OBJECT
public:
wwActiveLabel
(QWidget *parent
= 0);
///< default constructor ~wwActiveLabel();
signals:
void doubleClicked(); ///< double click with LMB
void clicked(); ///< single click with LMB
void pressed(); ///< LMB pressed
void released(); ///< LMB released
void mouseOver(); ///< mouse pointer just entered the widget
void mouseOut(); ///< mouse pointer just left the widget
protected:
bool hitLabel
(const QPoint &p
);
bool m_pressed;
};
#endif
/***************************************************************************
* Copyright (C) 2004 by Witold Wysota *
* wysota@wysota.eu.org *
* *
***************************************************************************/
#ifndef WWCLASSES_H
#define WWCLASSES_H
#include <QLabel>
#include <QTimer>
#include <QPoint>
/**
* @class wwActiveLabel
* @brief Label with mouse click and mouse move support
*
*
*/
class wwActiveLabel : public QLabel
{
Q_OBJECT
public:
wwActiveLabel(QWidget *parent = 0); ///< default constructor
~wwActiveLabel();
signals:
void doubleClicked(); ///< double click with LMB
void clicked(); ///< single click with LMB
void pressed(); ///< LMB pressed
void released(); ///< LMB released
void mouseOver(); ///< mouse pointer just entered the widget
void mouseOut(); ///< mouse pointer just left the widget
protected:
void mouseDoubleClickEvent ( QMouseEvent * e );
void mousePressEvent( QMouseEvent *e);
void mouseReleaseEvent( QMouseEvent *e);
void enterEvent(QEvent *);
void leaveEvent(QEvent *);
bool hitLabel(const QPoint &p);
bool m_pressed;
};
#endif
To copy to clipboard, switch view to plain text mode
***************************************************************************
* Copyright (C) 2004 by Witold Wysota *
* wysota@wysota.eu.org *
* *
***************************************************************************/
#include "wwclasses.h"
#include <QMouseEvent>
m_pressed = false;
setText("wwActiveLabel");
}
wwActiveLabel::~wwActiveLabel() {}
void wwActiveLabel
::mouseDoubleClickEvent( QMouseEvent * e
) { if(e->button() == Qt::LeftButton)
emit doubleClicked();
QLabel::mouseDoubleClickEvent(e
);
}
void wwActiveLabel
::mousePressEvent( QMouseEvent * e
) { if(e->button() == Qt::LeftButton) {
m_pressed = true;
} else
m_pressed = false;
emit pressed();
}
void wwActiveLabel
::mouseReleaseEvent( QMouseEvent * e
) { if(m_pressed && e->button() == Qt::LeftButton && hitLabel(e->pos()))
emit clicked();
m_pressed = false;
emit released();
}
void wwActiveLabel
::enterEvent( QEvent *e
) { emit mouseOver();
}
void wwActiveLabel
::leaveEvent( QEvent *e
) { emit mouseOut();
}
bool wwActiveLabel
::hitLabel( const QPoint & p
){ return rect().contains(p);
}
***************************************************************************
* Copyright (C) 2004 by Witold Wysota *
* wysota@wysota.eu.org *
* *
***************************************************************************/
#include "wwclasses.h"
#include <QMouseEvent>
wwActiveLabel::wwActiveLabel(QWidget *parent) : QLabel(parent) {
m_pressed = false;
setText("wwActiveLabel");
}
wwActiveLabel::~wwActiveLabel() {}
void wwActiveLabel::mouseDoubleClickEvent( QMouseEvent * e ) {
if(e->button() == Qt::LeftButton)
emit doubleClicked();
QLabel::mouseDoubleClickEvent(e);
}
void wwActiveLabel::mousePressEvent( QMouseEvent * e ) {
if(e->button() == Qt::LeftButton) {
m_pressed = true;
} else
m_pressed = false;
emit pressed();
}
void wwActiveLabel::mouseReleaseEvent( QMouseEvent * e ) {
if(m_pressed && e->button() == Qt::LeftButton && hitLabel(e->pos()))
emit clicked();
m_pressed = false;
emit released();
}
void wwActiveLabel::enterEvent( QEvent *e ) {
QLabel::enterEvent(e);
emit mouseOver();
}
void wwActiveLabel::leaveEvent( QEvent *e ) {
QLabel::leaveEvent(e);
emit mouseOut();
}
bool wwActiveLabel::hitLabel( const QPoint & p ){
return rect().contains(p);
}
To copy to clipboard, switch view to plain text mode
Bookmarks