c++ - QWidget on Mac OS X not focusing in Qt 5.x -
i have qsystemtrayicon qaction opens new window of type qwebview. when window loses focus , select qaction again, window should regain focus. on linux, doesn't on mac os x. problem is, when have window open , active, let's google chrome, when call show() on window i'm trying open, gets opened under google chrome, don't see it. same goes focusing, when have multiple windows open, , qwebview might last 1 in order, when click qaction focus window, under google chrome window. guess is, when click qaction, part of application's process, try open/focus window, in middle of operation, google chrome window gets scheduled , gains focus, since qsystemtrayicon cannot hold focus. because of that, when window gets opened/focused, not steal focus google chrome, because operating system not allow it, placed under focused window.
here how create/focus window:
// ... qpointer<qwebview> view; // ... void trayicon::webview() { if (!this->view) { this->view = new qwebview(); this->view->load("http://example.com"); this->view->show(); } else { this->view->activatewindow(); this->view->raise(); } }
is there incorrectly or there known workaround?
a bit offtopic, may usefull users:
my proposal create platform-depended code force raising of window. there same problem on windows platform, i'm using next hack:
void utils::forceforegroundwindow( wid winid ) { #ifdef q_os_win hwnd hwnd = winid; if ( ::iswindow( hwnd ) ) { hwnd hcurrwnd; int imytid; int icurrtid; hcurrwnd = ::getforegroundwindow(); imytid = ::getcurrentthreadid(); icurrtid = ::getwindowthreadprocessid( hcurrwnd, 0 ); ::attachthreadinput( imytid, icurrtid, true ); ::showwindow( hwnd, sw_shownormal ); ::setforegroundwindow( hwnd ); ::attachthreadinput( imytid, icurrtid, false ); } #endif }
i still not provide mac os compatibility in project, code has no functionality non-win platforms.
another idea: should keep focused visible window. try 1 wa_translucentbackground | wa_transparentformouseevents attributes + framelesswindowhint flag. application never loose focus.
Comments
Post a Comment