Event filter
-
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...
-
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...
-
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. -
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...
-
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;
}
@ -
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