Window is not in focus when opened
I'm opening a window widget from code. When that happens I already have 2 dialogs open.
QHBoxLayout *rev_Title = new QHBoxLayout; QFont f( "Arial", 18, QFont::Bold); revTitle->setFont (f); revTitle->setText ("Review the Data You Entered"); rev_Title->addWidget (revTitle,Qt::AlignCenter); review_Window->setWindowTitle ("Review"); rev_Layout->addLayout (rev_Title); review_Window->isModal (); review_Window->show (); review_Window->setFocus ();
Everything works nicely, but the new window is hidden between the 2 previously opened windows so it is not in the foreground. How can I open it in a way that it stays in the foreground and has the focus on it?
you can try to call
If you mean stay on top at ALL times then
there is a flag for that
you can use with setWindowFlags
-BUT- it makes windows stay above all others all the time.
Not sure you want that.
I made the following changes:
setWindowFlags (Qt::Popup); review_Window->setWindowTitle ("Review");
The new window does stay on top. I have 3 dialogs open:
Review_window is generated by additem. When review_window opens (and stays on top) it closes additem which I still need open. How can I keep additem open?
Hi you must show the code for how you open
additem and review_Window
as there is no reason for review_window to close additem so I assume
its something with your code. Like using exec instead of show or
using a local variable for additem so it runs out of scope and be deleted.
Here is the code opening additem:
Additem mAddItem; mAddItem.setModal (true); mAddItem.exec ();
and this opens review_Window:
review_Window->isModal (); review_Window->show (); review_Window->setFocus ();
Thank you for your help.
is local variable it seems but you are using exec() should should not run out of scope.
Please put a break point on next line after
and see if it for some reason falls out of exec() when u open review_Window.
Do you use a slot/button to call the code that opens review_Window?
Additem mAddItem; mAddItem.setModal (true); mAddItem.exec (); break;
generated an error message: break statement is not within a loop or switch.
Yes, the review_Window is opened in a function triggered by a slot/button.
i imagined something like
int a=100; <<< break point here.
Additem mAddItem; mAddItem.setModal (true); mAddItem.exec (); int a = 100;
Nothing really happened except I got a message saying unused variable.
did it stop at break point when review_window open?
meaning it went from
mAddItem.exec (); << should stay here
int a = 100; << should not go to this line when review_window
this is how u open review_Window still ?
Else Im afraid I cant guess what you are doing wrong.
Normally its not an isses to have 2 dialogs so must be some small details.
So u are almost there:)
It did not stop at breakpoint.
I open review_Window like this:
review_Window->setFocus (); review_Window->show ();
I haven't changed anything. Now all 3 windows (mainwindow, additem, review_Window) stay open. They are stacked from top to bottom like this: additem, review_Window, mainwindow. The minimize button doesn't work when all 3 windows open. If I close one of them everything works. No idea why. Thank you for your help.
When you call exec on a dialog, it become modal.
This means that other windows are blocked. also including minimize button.
That might be the reason.
Thank you. I redid the code and it works now.