Hi, I want to add the clicked() signal to a QLabel.
Can any1 point me the right direction to take?
Printable View
Hi, I want to add the clicked() signal to a QLabel.
Can any1 point me the right direction to take?
Override QWidget::mousePressEvent() and/or QWidget::mouseReleaseEvent().
Emit the signal whenever you feel it's appropriate.. :)
:confused:
Im not sure I understand what you mean.
How and where can i override that event?
Is that a virtual function?
You can copy the code from wwActiveLabel. It should work fine without any changes (maybe one change is required, as widgets in Qt4 don't take the name argument in their constructors anymore).Quote:
Originally Posted by lewis
Ill use that, but only if Im not able to make it myself quickly enough... I'd like to learn how to :) , thx tho
I get errors like these when using wwActiveLabel:
error C2027: use of undefined type 'QMouseEvent': see declaration of 'QMouseEvent'
error C2227: left of '->button' must point to class/struct/union/generic type
if i include QMouseEvent, i get linking errors.
im using qt 4.1.4 commercial
What kind of errors do you get?
This compiles fine:
Code:
/*************************************************************************** * 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 * * */ { Q_OBJECT public: ~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 m_pressed; }; #endif
Code:
*************************************************************************** * Copyright (C) 2004 by Witold Wysota * * wysota@wysota.eu.org * * * ***************************************************************************/ #include "wwclasses.h" #include <QMouseEvent> m_pressed = false; setText("wwActiveLabel"); } wwActiveLabel::~wwActiveLabel() {} if(e->button() == Qt::LeftButton) emit doubleClicked(); } if(e->button() == Qt::LeftButton) { m_pressed = true; } else m_pressed = false; emit pressed(); } if(m_pressed && e->button() == Qt::LeftButton && hitLabel(e->pos())) emit clicked(); m_pressed = false; emit released(); } emit mouseOver(); } emit mouseOut(); } return rect().contains(p); }
Of course i had linking errors, i forgot to add it to my .pro file and regenerate the project file!!! dumb me!:o
If you use wwActiveLabel in a commercial product, please put a copyright notice somewhere in its docs and/or in the "about" window (if your app has one).Quote:
Originally Posted by lewis
its not for commercial use, its only a little educationnal game that will be used inside a small non-profit organization.
Thx for ur wwActiveLabel widget!
Hi Lewis, this is Oleg S, I have the same problem that you, how did you solve it?
These are the messages errors:
Thanks so much!!Quote:
error C2027: use of undefined type 'QMouseEvent'
c:\qt4.4.0\src\gui\kernel\qwidget.h(77) : see declaration of 'QMouseEvent'
error C2227: left of '->pos' must point to class/struct/union/generic type
Oleg S,
Code:
#include <QMouseEvent>