
Originally Posted by
Globulus
I am new in QT...
So, my question is clear for most of you, but I still dont understand,
how can I subclass QLabel to make my own enterEvent, leaveEvent, mousePressEvent, mouseReleaseEvent, to extend QLabel functionality.
And then use it in my .ui application?
Hi there,
I reply here instead of the previous post.
{
Q_OBJECT
public:
~MyLabel();
protected slots:
virtual void enterEvent
( QEvent * event
);
virtual void leaveEvent
( QEvent * event
);
virtual void mouseReleaseEvent
( QMouseEvent * event
);
};
{
}
MyLabel::~MyLabel()
{
}
void MyLabel
::enterEvent ( QEvent * event
) {
}
void MyLabel
::leaveEvent ( QEvent * event
) {
}
{
}
{
}
void MyLabel
::mouseReleaseEvent ( QMouseEvent * event
) {
}
class MyLabel : public QLabel
{
Q_OBJECT
public:
MyLabel(QWidget * parent = 0);
~MyLabel();
protected slots:
virtual void enterEvent ( QEvent * event );
virtual void leaveEvent ( QEvent * event );
virtual void mouseMoveEvent ( QMouseEvent * event );
virtual void mousePressEvent ( QMouseEvent * event );
virtual void mouseReleaseEvent ( QMouseEvent * event );
};
MyLabel::MyLabel(QWidget * parent) : QWidget(parent)
{
}
MyLabel::~MyLabel()
{
}
void MyLabel::enterEvent ( QEvent * event )
{
}
void MyLabel::leaveEvent ( QEvent * event )
{
}
void MyLabel::mouseMoveEvent ( QMouseEvent * event )
{
}
void MyLabel::mousePressEvent ( QMouseEvent * event )
{
}
void MyLabel::mouseReleaseEvent ( QMouseEvent * event )
{
}
To copy to clipboard, switch view to plain text mode
In order to use this widget in the QtDesigner...
1. remember the header file name of this class (i.e. MyLabel.h in this case)
2. go to QtDesigner and put a QLabel or QWidget into the form
3. and the promote the QLabel or QWidget to MyLabel.
Hope this helps.
Regards,
Bookmarks