PDA

View Full Version : Using controls in secondary window without deactivating first window?



durbrak
12th June 2009, 09:05
I've been struggling with a little problem.
Basically I have one application with two windows: WindowA and WindowB. WindowA is sort of like the main window while WindowB is a window with some buttons in it.

What I want to do is to have WindowA permanently be the activated (focused) window. So whenever I click on a button inside WindowB - WindowA should stay activated/focused.
Currently, when clicking on any button inside WindowB, it gets activated/focused.

What I've tried so far:


bool WindowB::event(QEvent *event)
{
if(event->type() == QEvent::WindowActivate)
{
event->accept();
m_windowA->activate();
return true;
}

return QWidget::event(event);
}
//This actually works quite well.
//However, clicking on any controls won't work
//(WindowB doesn't receive mouseReleaseEvent()'s :().


m_windowB->setFocusPolicy(Qt::NoFocus);
//Doesn't work at all (for my scenario).


m_windowB->setFocusProxy(m_windowA);
//I thought this was it, but somehow it didn't change anything in behavior.


void WindowB::mousePress/*Release*/Event(QMouseEvent *event)
{
QWidget::mousePress/*Release*/Event(event);
m_windowA->activate();
}
//This works, but it seems like too much of a dirty workaround.
//Isn't there a more elegant solution?

nish
12th June 2009, 09:26
instead of event() use WindowB::eventFilter() and set qApp->installEventFilter(WindowB);