Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window doesn't get focus when using Qt::X11BypassWindowManagerHint flag

Tags:

c++

qt

I need to create window, which always stays on top without borders and controls. So I did this:

MainWindow window;
window.show();

Where MainWindow class looks like this:

MainWindow::MainWindow(QWidget *parent) : QWidget(parent, 
Qt::Window | Qt::WindowStaysOnTopHint 
| Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint) {

}

void MainWindow::keyPressEvent(QKeyEvent *event){
    if(event->key() == Qt::Key_Escape){
        QApplication::exit();
    } else
        QWidget::keyPressEvent(event);
}

Which works, but not perfectly. After program is launched, the windows doesn't have focus, so you must first click on it.If I remove Qt::X11BypassWindowManagerHint, window gains the focus, but than it doesn't show at all workspaces (desktops).

Question 1: What does Qt::X11BypassWindowManagerHint actually do?

Question 2: How do I get this working?

like image 330
tomascapek Avatar asked Mar 14 '23 10:03

tomascapek


1 Answers

So I managed to dig through the docs.

Question 1: Qt::X11BypassWindowManagerHint results in window without border and no control from window manager at all (only at X11!).

Question 2: To get focus and enable keyboard input, it is necessary to call QWidget::activateWindow().

like image 199
tomascapek Avatar answered Apr 09 '23 01:04

tomascapek