Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Customize mouseReleaseEvent

    General and Desktop
    3
    5
    4519
    Loading More Posts
    • 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.
    • M
      MrNoway last edited by

      This mouseReleaseEvent is working fine,

      @void mouseReleaseEvent ( QMouseEvent * event );@

      @void Lines::mouseReleaseEvent ( QMouseEvent * event ) {

      if ( event->button() == Qt::LeftButton)

      {
      msgBox = new QMessageBox();
      msgBox->setWindowTitle("Hello");
      msgBox->setText("You Clicked Left Mouse Button");
      msgBox->show();
      }
      }@

      But I need this to work only on a specific widget.

      so something like

      @ if ( event->button() == Qt::LeftButton) && ( widget == widget_1 )
      { do something}@

      @ if ( event->button() == Qt::LeftButton) && ( widget == widget_2 )
      { do something_else}@

      Can anyone help me please,
      I have been searching like for ever.

      I know I can do it via checking the x-y pos
      @if (( event->button() == Qt::LeftButton) && ((event->pos().x() <=20) ))@

      But this checks the total position,
      so if I move widget the coordinates are not correct anymore.

      1 Reply Last reply Reply Quote 0
      • B
        b1gsnak3 last edited by

        event->pos() == widget->pos() ?

        Or you can reimplement the mouseReleaseEvent for the widget you are trying to get the event from. It should overwrite the event from the parent in theory. May be speaking nonsense as I am not entirely sure. I know that for keyPressEvents this is happening.

        1 Reply Last reply Reply Quote 0
        • G
          giesbert last edited by

          This works in the class where you implement it. You can add a flag to the class that is checked whether the handling should be done or not.
          Or you use event filters for that.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply Reply Quote 0
          • M
            MrNoway last edited by

            thanks for your answers,
            but you could provide little bit of code, pelase.

            I have been trying but nothing really works.

            1 Reply Last reply Reply Quote 0
            • G
              giesbert last edited by

              which code should I provide?
              I have no need for this feature :-)
              I give you hints, you implement it, that's the way it works...

              So, if you have a custom widget class, e.g. MyLineEdit derived from QLineEdit, you overwrite mouseReleaseEvent as in your first post.
              Your class gets a poroperty: handleMouseRelease and depending on the value of that property, you handle it or not.

              Other option: The container creates an eventFilkter on clients (look at QObject and search eventFilter) and you handle it there.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply Reply Quote 0
              • First post
                Last post