Results 1 to 8 of 8

Thread: QMdiArea unwanted actvation

  1. #1
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QMdiArea unwanted actvation

    I'm using a QMdiArea as the central widget of my application and one of its subwindow itself contains another QMdiArea. As long as I keep my application on top of others everything *looks* fine but when I switch to another window and switch back to my app I face the weirdest (and among the most annoying) issue I've ever faced in Qt : QMdiArea automatically changes the active subwindow to the one owning another QMdiArea... I've any sort of software lock (signals based) I could think of, even tried to force the QMdiArea to set back the previous subwindow by keeping track of it but it just does not work...
    I read the docs again and again and found no clues... Just to make sure the problem does not come from my code I checked another app using the same QMdiArea nesting and was able to reproduce the bug... Does anyone have a magic trick or do I need to go on the tracker and wait for a couple of releases to have it fixed?
    Current Qt projects : QCodeEdit, RotiDeCode

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMdiArea unwanted actvation

    Would you mind attaching the test app so we can play around with it? Looks like QMdiArea does some nasty activation tricks upon QEvent::WindowActivate. Perhaps you could try filtering it (and possibly QEvent::WindowDeactivate too) out from the inner QMdiArea...
    J-P Nurmi

  3. #3
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMdiArea unwanted actvation

    hi,
    does it happens also when mdiArea in child window have no children? i would suspect that activation of child window may bring mdiArea to front, but it's only a speculation...

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMdiArea unwanted actvation

    Quote Originally Posted by jpn View Post
    Would you mind attaching the test app so we can play around with it? Looks like QMdiArea does some nasty activation tricks upon QEvent::WindowActivate. Perhaps you could try filtering it (and possibly QEvent::WindowDeactivate too) out from the inner QMdiArea...
    Thanks for the hint I'll try that. FYI the test apps are Edyuk 1.0.0 (SVN HEAD) and Monkey Studio 2 (still in private beta test so I can't redistribute it) but I'm willing to bet that the simplest subset of nested QMdiArea will yeld the same activation behavior...

    does it happens also when mdiArea in child window have no children? i would suspect that activation of child window may bring mdiArea to front, but it's only a speculation...
    I have no idea... The child mdi area always have at least a child (always a single one in Edyuk and one or more in Monkey Studio...)
    Current Qt projects : QCodeEdit, RotiDeCode

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMdiArea unwanted actvation

    Quote Originally Posted by fullmetalcoder View Post
    Just to make sure the problem does not come from my code I checked another app using the same QMdiArea nesting and was able to reproduce the bug...
    I somehow expected this to be a minimal compilable example or something like that.

    Does anyone have a magic trick or do I need to go on the tracker and wait for a couple of releases to have it fixed?
    The "magic trick" goes here:
    Qt Code:
    1. class InnerMdiArea : public QMdiArea
    2. {
    3. public:
    4. InnerMdiArea(QWidget* parent = 0)
    5. : QMdiArea(parent) { }
    6.  
    7. bool eventFilter(QObject* object, QEvent* event)
    8. {
    9. return event->type() == QEvent::ApplicationActivate
    10. || event->type() == QEvent::ApplicationDeactivate;
    11. }
    12. };
    To copy to clipboard, switch view to plain text mode 
    As the class name suggests, use this as the inner MDI area and everything should be fine.

    PS. The reason this works is that QMdiArea installs an event filter on QApplication and QObject::eventFilter() is virtual..
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    fullmetalcoder (10th November 2007)

  7. #6
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMdiArea unwanted actvation

    Neat! It works just fine but the only limitation is that it take place in the inner area which is loaded from a plugin so it will put some restrictions on plugins development. Better than nothing anyway...
    Current Qt projects : QCodeEdit, RotiDeCode

  8. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMdiArea unwanted actvation

    Quote Originally Posted by fullmetalcoder View Post
    It works just fine but the only limitation is that it take place in the inner area which is loaded from a plugin so it will put some restrictions on plugins development.
    Well, in that case you could do it differently. Just detect such nested mdi area in a way or another and do:
    Qt Code:
    1. qApp->removeEventFilter(innerMdiArea);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  9. #8
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMdiArea unwanted actvation

    You may also implement eventFilter in some external QObject and install it after QMdiArea creation from plugin.

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.