2

I have two GUI applications. The Master has to start the Slave. The Master has to start on the foreground, the slave has to start on the background. The slave has to come to the foreground later.

Is there a way to achieve this using Qt?

attempt so far:

... 
if( master() ) {
  window->show();
} else {
  window->showMinimized();
}

showMinimized() has the nasty side-effect that when the slave comes to the foreground first, it gets 'maximized'.

So is there a way to start an application behind another application?

xtofl
  • 40,723
  • 12
  • 105
  • 192

1 Answers1

2

One possibility is to explicitly call raise() or lower() on the respective windows (see docs). It's possible that this may result in a momentary visual glitch though, where the window briefly appears then gets pushed to the back, which may or may not be acceptible. I was going to suggest using QWidget::activateWindow() to force an application to the foreground, but the docs note that this is disallowed on Windows.

The other option would be to try to stop the widget becoming activated. I've had a quick look at the Qt source of QWidgetPrivate::show_sys() (in src/gui/kernel/qwidget_win.cpp). There appears to be an attribute Qt::WA_ShowWithoutActivating which dictates how the window gets shown. It looks like this may solve your problem, eg see Show window in Qt without stealing focus

Community
  • 1
  • 1
the_mandrill
  • 29,792
  • 6
  • 64
  • 93