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:

    But for some reason my Qlabel_mouseevent class(my_label in video) seems to be different when i create it.


    #include <QWidget>
    class Qlabel_mouseevent : public QLabel

  • Qt Champions 2017

    Hi what you have is just new class.
    You did not override mousepress

    they look like
    void mousePressEvent(QMouseEvent * event);
    void mouseReleaseEvent(QMouseEvent * event);

    please see this :)

  • This post is deleted!

  • @mrjj I still don't get how to make mouse event on qlabel active only when a putton is pressed and once it gets the value of roi it again act as normal qlabel

  • Qt Champions 2017

    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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.