QDesktopServices::openUrl alternative that does not give focus?
-
Is there a platform-independent way to open URLs in Qt (C++) without my application giving up the active state? Like the behavior you get when you middle-click on a link in modern web browsers. I'm currently using QDesktopServices::openUrl as the title indicates, but it can only open URLs and bring the browser to the front. Cocoa, for example, has a
@
openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:
@
in NSWorkspace that does the trick, but I can't find anything like it in Qt. Even QProcess doesn't seem to have the ability to start a (GUI) process without it stealing the focus. -
[quote author="uranusjr" date="1381309693"]Even QProcess doesn't seem to have the ability to start a (GUI) process without it stealing the focus.[/quote]
Did you try with "QProcess::start":http://qt-project.org/doc/qt-5.0/qtcore/qprocess.html#start ? (i.e. don't use QProcess static functions)
From what I remember this does the trick that you want.
-
Actual code:
@
// url is passed in as an argument
QProcess *p = new QProcess();
p->connect(p, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(deleteLater()));
QStringList args;
args << url;
p->start(PATH_TO_A_BROWSER, args);
@
and the browser takes the focus when it launches. Doesn't work for me (Qt 5.1 MinGW on Windows 8 x64). -
Ok, I don't remember exactly what I did with QProcess, but it works somehow with Qt 4.8.4
Anyway, as a workaround (I know it's uggly), maybe you can try to bring your main widget to top level after QProcess has finished:
@
mainWidget->activateWindow();
mainWidget->raise();
@