Mouse Event on Qlabel?
-
I have a button , a Qlabel and 4 double variables say x,y,width and height.
Now what i want is that once i click button and then go to the qlabel i can get the coordinated of the roi selected by mouse pressed and released event ?
For getting coordinate on Qlable I watched this Video:
https://www.youtube.com/watch?v=d0CDMtfefB4But for some reason my Qlabel_mouseevent class(my_label in video) seems to be different when i create it.
#ifndef QLABEL_MOUSEEVENT_H
#define QLABEL_MOUSEEVENT_H#include <QWidget> class Qlabel_mouseevent : public QLabel { public: Qlabel_mouseevent(); }; #endif // QLABEL_MOUSEEVENT_H
-
@vasu_gupta
Hi what you have is just new class.
You did not override mousepressthey look like
protected:
void mousePressEvent(QMouseEvent * event);
void mouseReleaseEvent(QMouseEvent * event);please see this :)
https://wiki.qt.io/Clickable_QLabel -
This post is deleted!
-
Hi
If you do not do
void ClickableLabel::mousePressEvent(QMouseEvent* event) {
emit clicked();
}then it will be a normal label
so if only allowed to be clicked after some button pressed ( not toggle ?)
you need to tell it to stop emit.
You can try to set use setDisabled
void QWidget::setDisabled(bool disable)when you set them back to "normal"
so they wont be clickable.