Confused about tofront

I have a program on a raspberry pi in which I have a rotary encoder connected. When I press the encoder a popupmenu is displayed. Rotating the encoder moves the selection on the menu, then pressing the button closes the menu.

The problem I have this: I have several non dialog windows open, and I want the selection to call a toFront on a particular windows. The toFront calls will not bring the dialog to the front. Is there something special about toFront on a non-modal dialog?

IIRC toFront brings a component to the front only inside its own parent component.

Is there a way to do it from outside the component?

Some of the answers in this thread could be helpful. You might be able use Process::makeForegroundProcess() or do some trickery with setAlwaysOnTop() to get the results you want.

I thought about that. So instead of toFront, I call setAlwaysOnTop true. (no dlgs had always on top set)

I assumed this would bring the dlg to the front but that did not work either.

How are you showing the DialogWindows? Using addToDesktop()? Some examples of the code you’re using might be helpful.

FWIW I just ran two quick tests on MacOS using toFront() with a few DialogWindows, and it brought the windows to the front as you’d expect. I tested with the windows added to the desktop using addToDesktop(), and with them added to the MainComponent as child components using addAndMakeVisible().

I’m not sure if the toFront() behavior varies between MacOS and Linux, but there might be something else going on that’s causing the window to not gain focus.

This is a huge application, so posting the whole this is out. The MainComponent windows is the one giving me trouble. The others seem to got to the top without help.

Yes, the windows are all added to the desktop. The one trying to push the maincomponent to the front is opened from the maincomponent like this:

         ChannelDlgPM = new ChannelDlgPMWindow(g_CurrentMix, true, true);

The ChannelDlgPMWindow constructor:

ChannelDlgPMWindow::ChannelDlgPMWindow(int ch, bool master, bool ignore)
: DialogWindow(TRANS(“Stereo Mix-Master”),
m_dlg = new ChannelDlgPM(ch, master, ignore);
setTitleBarButtonsRequired(maximiseButton|minimiseButton, false);
setResizable(true, true);
setContentOwned (m_dlg, true);
setVisible (true);


Is it because the MainComponent window is the one I’m trying to manipulate?

PS "How do I get code to format here?"

One of the following:

  • Put three backticks ``` before and after your code snippet, surrounding it
  • Indent every line in your code snippet with four spaces
  • Select the code snippet while editing the message, and press the tool button with this icon on it: </>. It will apply one of the two methods above to the snippet, don’t remember which

I have a little more info about the problem. When I open the popup menu a dialog is in front of the MainComponent. WIth my menu I select an item that should bring the maincomponent to the front, but it does not. If I do it a second time, the then brings it to the front.

So I installed codeblocks for debugging. Set a breakpoint on the used for the popup menu, and a break on the line following the It breaks on the call. If I continue the menu pops up. When I make the selection, the maincomponent comes to the front, then I hit the breakpoint. It is as if the previous tofront was queued for later, then unqueued by the

A little more background. The gpio pins used for reading the rotary encoder and read from a timer callback, so the and calls tofront are issued by the timer thread. I have no idea if this has anything to do with it.

As another test, I set a timer to bring several windows to the top one at a time every 5 seconds. This worked on all windows except MainComponent. I could see that it got focus because the top of the window was visable and it title bar brightens like when you click on it but the window did not come to front.
Xenakios said: IIRC toFront brings a component to the front only inside its own parent component.

So I created a global flag(just for testing…) and set it when I wanted the maincomponent in from. I then setup a timer in maincompont and check the flag and if set call toFront(true). This did not work either. I then tried calling getParentCompoent()->toFront(true) and this doesn’t work either.

I’m pulling out my hair trying to figure this out and I haven’t much hair left…