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=d0CDMtfefB4

    But 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
    

  • Qt Champions 2016

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

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

    please see this :)
    https://wiki.qt.io/Clickable_QLabel



  • 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 2016

    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.


Log in to reply
 

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