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. How to use eventFilter()?
QtWS25 Last Chance

How to use eventFilter()?

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

    in A widget,i use
    @
    virtual void mousePressEvent(QMouseEvent *);
    virtual void mouseReleaseEvent(QMouseEvent *);
    virtual void mouseDoubleClickEvent(QMouseEvent *);
    @
    but i find i can't distinguish clike and doubleclike,so i want to use eventFilter() to distinguish. but i write
    @
    installEventFilter(this); // this is a widget,
    bool CSSEMainViewPro::eventFilter(QObject *object, QEvent event)
    {
    qDebug()<<"eventFilter";
    if (object == this)
    {
    if(event->type() == QEvent::MouseButtonPress)
    {
    QMouseEvent
    pMouseEvent = static_cast<QMouseEvent >(event);
    mousePressEvent( pMouseEvent );
    return true;
    }
    if(event->type() == QEvent::MouseButtonRelease)
    {
    QMouseEvent
    pMouseEvent = static_cast<QMouseEvent >(event);
    mouseReleaseEvent(pMouseEvent);
    return true;
    }
    if(event->type() == QEvent::MouseButtonDblClick)
    {
    QMouseEvent
    pMouseEvent = static_cast<QMouseEvent *>(event);
    mouseDoubleClickEvent(pMouseEvent);
    return true;
    }
    }
    return QWidget::eventFilter(object,event);
    }
    @
    but eventFilter()can't be use .how to use it?

    edit: fixed your use of @ tags;Andre

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Is CSSEMainViewPro a subclass of QWidget?

      BTW,

      1. What you do is exactly the default behavior of mousePressEvent(...),...
      2. There is no need to install a eventfilter to itself, all the event can be dealt with in event() .
      1 Reply Last reply
      0
      • F Offline
        F Offline
        foxgod
        wrote on last edited by
        #3

        but i want to distinguish clike and doubleclike,how to do ?QTimer can't come ture;and i must use
        @
        virtual void mousePressEvent(QMouseEvent *);
        virtual void mouseReleaseEvent(QMouseEvent *);
        virtual void mouseDoubleClickEvent(QMouseEvent *)
        @
        yes,CSSEMainViewPro is a subclass of QWidget?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dbzhang800
          wrote on last edited by
          #4

          In fact, there is no way to distinguish a mouse press-release is a single-click or part of a double-click.

          press ... release(single-click) ... press ... release(double-click)

          You don't know whether the first press...release is a real single-click or not, unless you wait a short time to make sure that there will no another press...release.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            There is no way to distinguish, as 1+1=2 rightly says. Normally, a single click would be a select/make current action, while the double click would perform a default action on that (now current) item. So, the click and double click would be a logical sequence.

            If you can't make your application work that way, the only thing you can do is to not directly execute the action attached to the click. Instead, you'd wait a little to see if the click turns into a double click or not. Anyway, you're not the first to ask this question. I posted my solution in "a previous topic":/forums/viewthread/26039 on this issue. Note that it does use eventFilter, but not in the way you tried to use it.

            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