Here is what I want to do :
Check if my Qt app on windows is an app on the front or minimized.
If its minimized then draw the users attention by making it blink.
Now how can i detect if the app is minimized or on the background ?
I believe this is what you are looking for:
http://qt-project.org/doc/qt-5/qwidget.html#isActiveWindow-prop
then, you can call QWidget::activateWindow().
Looking at the notes:
if you are calling this when the application is not currently the active one then it will not make it the active window. It will change the color of the taskbar entry to indicate that the window has changed in some way.
This sounds exactly like this blink effect you are trying to achieve.
(Links are for Qt5, but this already exists in Qt4: http://qt-project.org/doc/qt-4.8/qwidget.html#activateWindow)
Related
I want to save the focused window's title, i made this part but i dont know is there any QEvent which catches all (non-application) focusChanged event? Like switching from Chrome to Qt Creator. I made an alternative solution that checks in every second if the topmost window title has changed but this is so rude. I need cross-platform solution if possible.
EDIT
I am using QT 5.9.0
Quick answer:
Qt only has focus events for it's own windows and widgets. See http://doc.qt.io/qt-5/qfocusevent.html#details for start point.
There is no event for focus in other applications.
Details:
For multi-platform solution is needed to have more general point of view. On some (X window) systems where keyboard focus is in window under mouse. But that window becomes topmost only after click. On Mobile platforms there is only one active application. And application is not allowed seeing when other applications are activated. So in my understanding there is no full multi-platform solution.
Windows only extensions are in the Qt Windows Extras. http://doc.qt.io/qt-5/qtwinextras-overview.html. But there is nothing focus change related unfortunately.
I am writing an QT application that embeds Mplayer on Ubuntu unity. I want to project videos on a projector in a dance show. I therefore have created a second form, which I move to the second screen and make it fullscreen.
Here is how I did it:
void MainWindow::on_testdialog()
{
QScreen *secondscreen = QApplication::screens()[1];
outputform->move(secondscreen->geometry().x(),secondscreen->geometry().y());
outputform->resize(secondscreen->geometry().width(),secondscreen->geometry().height());
outputform->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
outputform->setWindowState(Qt::WindowFullScreen);
outputform->show();
}
Then I redirect the Mplayer output to this form.
This works, however sometimes the second form is true fullscreen and sits on top of the Ubuntu unity menu pane (the one on top) and sometimes the Ubuntu unity menu pane is on top.
It seems to me that it is randomly doing this.
I would like my form to be always on top, because I don't want the menu pane to show up on stage.
Is there a way to do this?
Is there a reason for this, seamingly, random behavior? maybe a bug in Ubuntu?
Kind regards,
Bart.
This sounds like a problem of the window manager which makes it out of reach for Qt to solve. Qt is only setting the corresponding WM hints on the window and hopes for the window manager to do the right thing.
For your application I suggest you install a lightweight window manager like Openbox or Fluxbox that will more likely stay out of the way. After installation you can choose it in the login screen.
I have created a windows application in C++ and I want to make so whenever I run it, it doesn't steal focus from whichever window is currently focused(or maybe steal the focus and give it back right away). I'm not creating any window so i'm not sure how to change the window style, my program runs in the background.
I couldn't find any answer that worked for C++, is there any way I can do this?
When you start your application by clicking on the EXE or shortcut, Windows Explorer takes focus, not your app. The only way to start your app and not let Windows Explorer take focus is to start your program when Windows starts, via registry key.
Make sure you use the extended style WS_EX_NOACTIVATE when using CreateWindowEx().
See the Microsoft Docs for CreateWindowEx.
Currently whenever my application starts it does not appear in the foreground. It appears on the taskbar but it does not get focus. I tried doing the following
application.setActiveWindow(&w);//w if my form widget
but this just makes it blink. Any suggestion on how I could set the focus to my application.
How can I make my application always be on top meaning that the user couldn't access start menu or desktop in Qt or any other possible c++ way?
Also i need it to start right after the login progress , more like a new gui for windows , a simpler one
QWidget::setWindowFlags(Qt::WindowStaysOnTopHint) should do the trick. Note that on some window managers on X11 you also have to pass Qt::X11BypassWindowManagerHint for this flag to work correctly.