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. Customize mouseReleaseEvent

Customize mouseReleaseEvent

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.9k 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.
  • M Offline
    M Offline
    MrNoway
    wrote on last edited by
    #1

    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
    0
    • B Offline
      B Offline
      b1gsnak3
      wrote on last edited by
      #2

      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
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        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
        0
        • M Offline
          M Offline
          MrNoway
          wrote on last edited by
          #4

          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
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            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
            0

            • Login

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