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. Event filter
Qt 6.11 is out! See what's new in the release blog

Event filter

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello, I removed native Menu with (Minimize, Exit) and created my own frame... I have a piece of code which handles mouse moving of my app... It reacts on whole app... I would like it to react only on menu frame... How can I handle moving only with top frame??? I tried to set event filters but without success...

    !http://imageshack.com/a/img203/8863/owtu.png(i)!

    @void MainWindow::mousePressEvent(QMouseEvent *event)
    {

     if (event->button() == Qt::LeftButton) {
         dragPosition = event->globalPos() - frameGeometry().topLeft();
         event->accept();
    
     }
    

    }

    void MainWindow::mouseMoveEvent(QMouseEvent *event)
    {

     if (event->buttons() & Qt::LeftButton) {
         move(event->globalPos() - dragPosition);
         event->accept();
    
     }
    

    }@

    P.S: I know I posted this once already, but was not a standalone topic...

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      If I install event on ui->centralWidget, then it affects all items... If I install event on ui->frame, then frame does not respond but else does...

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Hi,
        What do you want the mouseMove to do? I'm a bit puzzled here. If you want special mouseMove behavior simply setup the Frame::MouseMoveEvent and do some stuff in there. Or if the buttons need to light up? That may be done in the mousemoveevents of the buttons itself (loose focus/get focus).
        Describe what you want it to do in detail and we might be able to help or point you in the right direction.

        Greetz, Jeroen

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          I removed Native frame with setWindowFlags(Qt::FramelessWindowHint) and now I can't move my app around desktop... Now I want to set this top frame to have same function as native frame -> allow moving around application... My piece of code does that job, but it applies for a whole application - I can move around app if I click on top frame, or middle frame, or bottom frame... And I want only top frame to be able to move around app... I want mousemoveevent to execute only when top frame is pressed...

          *What I mean with move around... Since I've used setWindowFlags(Qt::FramelessWindowHint), when I execute app it's fixed... Can't move it left, right, etc, because there is no "Native top frame" which has Exit, Minimize, Maximize buttons and allow moving app around desktop...

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            Ahh, Got it.
            Let's think about that.
            Install the eventFilter to the centralWidget I guess and in that eventFilter check what object did the event to trigger. If the TopFrame did so, execute the event, if not, ignore the event
            @
            bool FilterFrame::eventFilter(QObject *object, QEvent *event)
            {
            if (object == TopFrame && event->type() == QEvent::MouseMove)
            {
            return true;
            }
            return false;
            }
            @

            Greetz, Jeroen

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NicuPopescu
              wrote on last edited by
              #6

              Hi,

              I think you should do the main window the event filter for your frame, by reimplemeting eventFilter() in it, move your mouse handling(your piece of code) into eventFilter, and filter out other senders for mouse move event ...or do subclass your frame from QFrame if not already) and move there the code for mouse handling

              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