Results 1 to 2 of 2

Thread: Using controls in secondary window without deactivating first window?

  1. #1
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Using controls in secondary window without deactivating first window?

    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:

    Qt Code:
    1. bool WindowB::event(QEvent *event)
    2. {
    3. if(event->type() == QEvent::WindowActivate)
    4. {
    5. event->accept();
    6. m_windowA->activate();
    7. return true;
    8. }
    9.  
    10. return QWidget::event(event);
    11. }
    12. //This actually works quite well.
    13. //However, clicking on any controls won't work
    14. //(WindowB doesn't receive mouseReleaseEvent()'s :().
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. m_windowB->setFocusPolicy(Qt::NoFocus);
    2. //Doesn't work at all (for my scenario).
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. m_windowB->setFocusProxy(m_windowA);
    2. //I thought this was it, but somehow it didn't change anything in behavior.
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void WindowB::mousePress/*Release*/Event(QMouseEvent *event)
    2. {
    3. QWidget::mousePress/*Release*/Event(event);
    4. m_windowA->activate();
    5. }
    6. //This works, but it seems like too much of a dirty workaround.
    7. //Isn't there a more elegant solution?
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using controls in secondary window without deactivating first window?

    instead of event() use WindowB::eventFilter() and set qApp->installEventFilter(WindowB);

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.