QDialog as Popup does not hide on Mac when clicking out of the main window - c++

I have a basic QDialog with it's WindowFlags set to Qt::Popup so that it appears as a typical popup overlay.
On Windows, everything works great and if you click outside the main window or really anywhere else it goes away. But on Mac OSX, if you click the menu bar at the top or resize the window, the popup just stays where it is. I have absolutely no internal handling of the mouse enter/leave/move/press events for the popup, so the closing of it is not something I'm even handling... it's just automatic on Windows.
Any idea I can get it to close when the main application is no longer the current context on the system?

You may install native event filter and to close active popup dialog (QApplication::activePopupWidget()) when user will click out of main window. See the following answer for information how to install native filter.

Related

How to programmatically close wxMenu used as popup menu via `wxWindow::PopupMenu` in wxWidgets?

I have a set of instances of plotting view that's added/removed dynamically according to incoming signals from tcp port from another process.
In each instance, the user can right click to open a popup menu, invoked via wxWindow::PopupMenu.
If the plotting view instance is to got shutted-down dynamically while the popup menu is visible, the view instance window is closed while the popup menu is still floating. Then any GUI action crashes the application.
I've been going through the APIs for wxWidgets to find a way to programmatically close the popup menu in the plotting view destructor, but with no-luck.
I found this forum post suggesting it's an impossible thing to close the popup menu programmatically. But it's too old, so not sure if it's still valid assumption.
Here are the trials that failed till now :
Trying to call SetFocus and SetFocusFromKbd on the plotting view as a way to move focus.
Generating mouse left click event and send it to the popup menu.
Generating a keyboard event and send it to the popup menu.
PlottingView::~PlottingView()
{
cout << "Sending wxMouseEvent to the popup menu" << endl;
wxMouseEvent e(wxEVT_LEFT_UP);
this->GetPopupMenu()->ProcessEvent(e);
wxKeyEvent ke(wxEVT_CHAR);
ke.m_keyCode = WXK_DOWN;
this->GetPopupMenu()->ProcessEvent(ke);
ke.m_keyCode = WXK_RETURN;
this->GetPopupMenu()->ProcessEvent(ke);
// the rest of the destruction
}
So I will appreciate any idea to programmatically close this popup menu.
Platform:
CentOS: 6.7
wxWidgets 2.8.12
G++: 4.3.3
Edit #1
Note: For commenters and answers suggesting upgrading the wxWidgets version, it's a debate in my team for everyday. But the answer is still no.
Most of the trials has failed. But I found a workaround to stop crashing but the popup menu don't close.
The solution was to nullify the following members using their setters, so the menu callback won't access them.
this->GetPopupMenu()->SetInvokingWindow(NULL);
this->GetPopupMenu()->SetEventHandler(NULL);
The best is probably to delay destroying the underlying window until PopupMenu() returns. As it is, your program logic is very convoluted because you're dispatching the event which results in closing of the window from inside PopupMenu() function and this just can't end well, even if you could use wxUIActionSimulator to close the menu (but you definitely should consider upgrading your 15 year old wxWidgets version in any case).

how to know a child window disappears(context menuor or tooltip etc) as soon as the parent window goes into background?

I have an application that sends instructions(click or find ) to windows that performs actions on the target windows application.But if the instruction is clicking on the file menu of a window which opens a context menu, the next instruction (select context menu item) should not fail if any other application come to foreground on the windows.
So before perfoming action, (checking isWindow is not accurate) need to find out the window still there? or
Is there something in the window properties that will tell me whether it stays or disappears as soon as other application gain focus?

Can't focus from main window after closing dialog from other thread

I create a new CWindThread in CWinApp::InitInstance(). In that thread, I create a dialog (for displaying a progress bar in that dialog).
After finishing InitInstance(), I close the dialog by calling DestroyWindow() from the dialog, but the application is loosing focus from main window.
I used AfxGetMainWnd()->SetActiveWindow(); to set focus for main window but it is not working.
How can I return the focus to the main window after closing the dialog?
There is no real good way to do that. The focus is set per thread. So there is no "focus" over all windows.
The only chance you have is to set the new foreground window, that belongs to the other thread with SetForegorundWindow. From within the same application this should work without restrictions.
If it doesn't work you need to "synch" both message queues. This is done by AttachThreadInput. If both messages queue are already attached, than there is no problem with settings the focus directly. But the behaviour of the application will change... Please read the docs, of the functions I linked too.
When a modal popup window is displayed, the reason a user cannot interact with the owner window is that it is disabled. When the modal window is destroyed, care must be taken to re-enable the owner window BEFORE destroying the popup as windows cannot activate a disabled window. This is the usual cause of popup windows re-activating the wrong window.

Qt how to create a settings/configuration window

I was trying to find an example of creating a settings/configuration windows. The settings window is launched by clicking "Options" action in the menu item. I wanted to figure out how to open up a 2nd window from the main window. As well how the new window return the settings information back to main window. Tried to play around with the QDialog or some inherited dialog classes, but those are for limited uses, not for general setting window. Is there any example/documentation about this?
Have you seen this property browser. Similar to property editor in Qt Designer. qtpropertybrowser Image

WS_EX_TOOLWINDOW issue

On Dialog based application, if you create a new dialog(tool window), and you press alt-tab, you can see the main dialog, and the tool window is missing( that is ok, is what a tool window is made to do).
On sdi/mdi applications if you open a tool window and press alt-tab, the application disappear from task bar(mainframe too). And that is my problem . I want my mainframe to always appear on task bar when I press alt-tab, even if a tool window is opened.
Any idea is appreciated.
Thank you.