PDA

View Full Version : How to keep window in foreground



szicsi
16th January 2008, 23:41
I'm very novice in Qt, but I made two widgets, one calls the others showEvent() and the second window pops up which has some checkboxes and a Cancel and Apply button.

Now I want to solve that user be forced to click either Apply or Cancel button, till that action he couldn't click on other window, so to remain alway active this new window.

Sorry if I haven't used correct terms.

wysota
17th January 2008, 00:08
I'm very novice in Qt, but I made two widgets, one calls the others showEvent()
Hmm??? What for? Can't you use QWidget::show()?



Now I want to solve that user be forced to click either Apply or Cancel button, till that action he couldn't click on other window, so to remain alway active this new window.

Derive that second widget from QDialog and pass the first widget as its parent in the constructor. Then call QDialog::exec() instead of QWidget::show() and you'll get the desired modal dialog.

szicsi
17th January 2008, 09:02
Thanks for help !
I used showEvent() because before showing the second window I wanted to do some settings in its widget.

So there isn't any simpler solution to keep the second window in foreground ?
I mean something that I could call a function of the second widget which keeps the second window in foreground (doesn't allow to activate other windows by clicking on them) and releases the window if I click its Apply os Cancel pushButton.

wysota
17th January 2008, 11:03
I used showEvent() because before showing the second window I wanted to do some settings in its widget.
This doesn't explain why you didn't use show().


So there isn't any simpler solution to keep the second window in foreground ?
The solution I gave you is a simple solution. It can't get any simpler.


I mean something that I could call a function of the second widget which keeps the second window in foreground (doesn't allow to activate other windows by clicking on them) and releases the window if I click its Apply os Cancel pushButton.

Keeping it in foreground is not enough because you could still interact with the first window. You have to make the dialog modal and for that it needs to actually be a dialog.

Read this too: http://www.qtcentre.org/forum/faq.php?faq=qt_general_category#faq_qt_designer_2f orms

szicsi
17th January 2008, 13:39
OK, I belive you, and as I said I'm not an expert in Qt.
I used showEvent() because I read about it:


void QWidget::showEvent ( QShowEvent * ) [virtual protected]
This event handler can be reimplemented in a subclass to receive widget show events.

So in my mind it was that this is a virtual method and I can reimplement it in may class which is inherited from QWidget and implement that second window.
So I reimplemented the showEvent() method: I did my necessary setting and finally I called the show() method which causes to appear the window itself which it implement.

This was my logic, maybe not the correct one but it works :)

Thanks for help !

wysota
17th January 2008, 15:40
You should have done that in the class constructor not in showEvent().