Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Mouse Event on Qlabel?
QtWS25 Last Chance

Mouse Event on Qlabel?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 4.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vasu_gupta
    wrote on last edited by
    #1

    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
    
    mrjjM 1 Reply Last reply
    0
    • V vasu_gupta

      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
      
      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @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

      V 1 Reply Last reply
      2
      • V Offline
        V Offline
        vasu_gupta
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • mrjjM mrjj

          @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

          V Offline
          V Offline
          vasu_gupta
          wrote on last edited by
          #4

          @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

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved