Results 1 to 6 of 6

Thread: How to keep window in foreground

  1. #1
    Join Date
    Jan 2008
    Posts
    3
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default How to keep window in foreground

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to keep window in foreground

    Quote Originally Posted by szicsi View Post
    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.

  3. #3
    Join Date
    Jan 2008
    Posts
    3
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to keep window in foreground

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to keep window in foreground

    Quote Originally Posted by szicsi View Post
    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.ph...esigner_2forms

  5. #5
    Join Date
    Jan 2008
    Posts
    3
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to keep window in foreground

    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 !
    Last edited by jpn; 18th January 2008 at 16:51. Reason: missing [quote] tags

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to keep window in foreground

    You should have done that in the class constructor not in showEvent().

Similar Threads

  1. Set a window as child at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2007, 09:30
  2. Change shape of window / animate window
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 31st October 2007, 08:16
  3. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  4. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 10:21
  5. QPalette won't set QLabel's Window & Foreground color
    By koklim in forum Qt Programming
    Replies: 6
    Last Post: 23rd January 2006, 10:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.