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. Qtreeview MouseEvent
Forum Updated to NodeBB v4.3 + New Features

Qtreeview MouseEvent

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 2 Posters 9.4k Views 2 Watching
  • 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.
  • S Offline
    S Offline
    Shiv
    wrote on last edited by
    #10

    Hi @mrjj

    Its not working for treeview .There are lot of widgets in my application to segregate the mouse press event i have used event filter.But i am unable to understand why the event filter is not working for treeview if possible can you check at your end .

    Thanks

    mrjjM 1 Reply Last reply
    0
    • S Shiv

      Hi @mrjj

      Its not working for treeview .There are lot of widgets in my application to segregate the mouse press event i have used event filter.But i am unable to understand why the event filter is not working for treeview if possible can you check at your end .

      Thanks

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #11

      @Shiv
      Hi
      Why not just override
      mousePressEvent(QMouseEvent *event)
      for treeview?
      I dont understand why you try with eventfilter even i completely agree
      all events should also be seen there.
      I will try eventfilter on tree and see if I get a hint.

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

        hi
        The Tree have a viewport that get these events
        so
        ui->listView->viewport()->installEventFilter(this);

        and

        bool MainWindow::eventFilter( QObject* watched, QEvent* event ) {
          qDebug() << "treeview event !1";
          QTreeView* view = qobject_cast<QTreeView*>(watched);
        
          QMouseEvent* k = static_cast<QMouseEvent*>(event);
        
          if(k) {
            if((k->button()) == Qt::LeftButton) {
              qDebug() << "treeview button down 3 ";
            }
          }
        

        worked for me.

        return QObject::eventFilter(watched, event);
        }

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Shiv
          wrote on last edited by
          #13

          Hi @mjrr
          Thanks for your valuable time and code.
          Its working fine with this code.The event is working fine in QT5.4 but I am currently doing this project in Qt 4.8.4 with VS2008 there some spurious events are getting generated without pressing the mouse.I am unable find the cause for this peculiar behavior. Any solution/idea will be helpful for me to move forward.

          Thanks

          mrjjM 1 Reply Last reply
          0
          • S Shiv

            Hi @mjrr
            Thanks for your valuable time and code.
            Its working fine with this code.The event is working fine in QT5.4 but I am currently doing this project in Qt 4.8.4 with VS2008 there some spurious events are getting generated without pressing the mouse.I am unable find the cause for this peculiar behavior. Any solution/idea will be helpful for me to move forward.

            Thanks

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #14

            @Shiv
            Hi, ok that is good to hear.
            Very hard to guess at when its other Qt and compiler :)

            You can use my event debug function
            http://paste.ofcode.org/xKREBjyuFwX6FEzTr4rRAP

            and call it with
            qDebug() << "EVENT: " << event->type() << " = " << EventDesc(event->type() );
            in the event filter to see if u can guess what is happening.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Shiv
              wrote on last edited by
              #15

              @mjrr
              I will try and let you know.
              Thanks

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Shiv
                wrote on last edited by
                #16

                Hi @mjrr
                I have tried with your EventDesc function the mouse press event automatically getting generating and it happens randomly I know its difficult to replicate this issue at your end i am posting some of the debug message kindly have look.The BTN variable is the mouseevent k->button() value

                //BTN k->button() value
                EVENT:  127  =   mouse cursor enters a hover widget 
                
                EVENT:  129  =   mouse cursor move inside a hover widget 
                BTN  2 
                EVENT:  12  =   paint widget 
                BTN  2347008 
                EVENT:  129  =   mouse cursor move inside a hover widget 
                BTN  2 
                EVENT:  129  =   mouse cursor move inside a hover widget 
                //BTN  1  // mouse event without mouse action
                //treeview button down 3  
                EVENT:  129  =   mouse cursor move inside a hover widget 
                //BTN  1 
                //treeview button down 3  
                EVENT:  129  =   mouse cursor move inside a hover widget 
                //BTN  1 
                //treeview button down 3  
                EVENT:  129  =   mouse cursor move inside a hover widget 
                BTN  1 
                treeview button down 3  
                EVENT:  129  =   mouse cursor move inside a hover widget 
                //BTN  1 
                //treeview button down 3  
                EVENT:  129  =   mouse cursor move inside a hover widget 
                //BTN  1 
                //treeview button down 3  
                EVENT:  129  =   mouse cursor move inside a hover widget 
                BTN  1 
                treeview button down 3  
                EVENT:  129  =   mouse cursor move inside a hover widget 
                BTN  2 
                EVENT:  110  =  Tooltip 
                BTN  0 
                EVENT:  129  =   mouse cursor move inside a hover widget 
                BTN  1 
                treeview button down 3  
                EVENT:  110  =  Tooltip 
                BTN  0 
                EVENT:  129  =   mouse cursor move inside a hover widget 
                BTN  0 
                EVENT:  129  =   mouse cursor move inside a hover widget 
                

                Thank you

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

                  hi
                  what about

                  
                  bool MainWindow::eventFilter( QObject* watched, QEvent* event ) {
                    qDebug() << "treeview event !1";
                    QTreeView* view = qobject_cast<QTreeView*>(watched);
                  
                    QMouseEvent* k = static_cast<QMouseEvent*>(event);
                  
                    if(k && k->type() == QEvent::MouseButtonPress) {
                      if((k->button()) == Qt::LeftButton) {
                        qDebug() << "treeview button down 3 ";
                      }
                    }
                    return QObject::eventFilter(watched, event);
                  }
                  
                  
                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Shiv
                    wrote on last edited by
                    #18

                    Hi
                    Great its working thanks a lot..
                    Thank you

                    mrjjM 1 Reply Last reply
                    0
                    • S Shiv

                      Hi
                      Great its working thanks a lot..
                      Thank you

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #19

                      super :)
                      Error was that we use
                      <QMouseEvent*>
                      and Hover is also such type , i think.
                      No idea why k->button() seems to be set for those but
                      with extra check it works then :)

                      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