1
votes

QWidget is created after some time in my app. I start my app. Then I use internet browser. On Linux my new widget appeares over my browser, but on Windows - not. Widget has parent widget. How to fix it on Linux?

both parent and my widget have only setFocusPolicy(Qt::StrongFocus); The Linux OS is Xubuntu. And one difference in parent class:

#if defined(Q_WS_X11) 
   setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); 
#else 
   setWindowFlags(Qt::Window | Qt::FramelessWindowHint); 
#endif
1
You should state which Lunix version you are using, and maybe add screenshots and the initialization code of your widget. - Tim Meyer
parent is QWidget too. both parent and my widget have only setFocusPolicy(Qt::StrongFocus); The Linux OS is Xubuntu. And one difference in parent class: #if defined(Q_WS_X11) setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); #else setWindowFlags(Qt::Window | Qt::FramelessWindowHint); #endif - alez

1 Answers

0
votes

I believe Windows prevents other programs from stealing the focus while some other OS may not enforce that.

When you create your widget, you should set the window state before making it visible. For instance

 QWidget* lateWidget = new QWidget(this); // or add to layout or whatever
 lateWidget->setWindowState(this->windowState());
 lateWidget->show();

Edit:

From the docs :

A widget that happens to be obscured by other windows on the screen is considered to be visible

Which means that if you open the browser on top of parent then lateWidget->show() will ask to the window system to be activated.lateWidget which then pop on top and gain user mouse and keyboard focus.

before showing lateWidget a quick fix is to use

 lateWidget->setAttribute(Qt::WA_ShowWithoutActivating);