Results 1 to 9 of 9

Thread: Open subwindow

  1. #1
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Open subwindow

    Hi!

    Although this is a often treated problem, I am confused about the thousand possibilities that exist to realise what I want.

    I have a slot being connected to a button that shall open a subwindow.

    - this subwindow is a subclass of QWidget
    - it shall not appear in the taskbar (on Windows)
    - it shall have a minimize-, maximize- and close-button
    - it shall have a system menu in the upper left corner
    - it shall be resizable
    - it shall be MODAL, the window containing the button to open the subwindow shall be blocked as long as the subwindow is open.

    So far I have the following:
    Qt Code:
    1. void MainWindow::openSubWindow()
    2. {
    3. SubWindowWidget w(customer);
    4. QDialog diag(0, Qt::Window );
    5. diag.setSizeGripEnabled(true);
    6. QHBoxLayout * lay = new QHBoxLayout;
    7. lay->addWidget(&w);
    8. diag.setLayout(lay);
    9. diag.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    First problem of this: the destructor of w is called twice!
    Can I somehow omit the usage of a QDialog?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Open subwindow

    try this
    Qt Code:
    1. void MainWindow::openSubWindow()
    2. {
    3. SubWindowWidget *w = new SubWindowWidget(customer);
    4. w->setAttribute(Qt::WA_DeleteOnClose);
    5. w->setAttribute(Qt::WA_ShowModal);
    6. w->show();
    7. // QDialog diag(0, Qt::Window );
    8. // diag.setSizeGripEnabled(true);
    9. // QHBoxLayout * lay = new QHBoxLayout;
    10. // lay->addWidget(&w);
    11. // diag.setLayout(lay);
    12. // diag.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following 2 users say thank you to spirit for this useful post:

    mattc (3rd June 2009), olidem (14th May 2009)

  4. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Open subwindow

    btw, customer is a widget?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #4
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Open subwindow

    NICE NICE NICE NICE !!!!

    Thx, this is what i was looking for.

    The only thing that is still not how I want it is the fact the the subwindow gets an entry in the Windows taskbar.

  6. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Open subwindow

    try this
    Qt Code:
    1. void MainWindow::openSubWindow()
    2. {
    3. SubWindowWidget *w = new SubWindowWidget(0);
    4. w->setAttribute(Qt::WA_DeleteOnClose);
    5. w->setAttribute(Qt::WA_ShowModal);
    6. w->show();
    7. }
    To copy to clipboard, switch view to plain text mode 
    that's why I was asking about customer.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #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: Open subwindow

    Quote Originally Posted by olidem View Post
    The only thing that is still not how I want it is the fact the the subwindow gets an entry in the Windows taskbar.
    Pass the main window as the parent of the dialog.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    olidem (14th May 2009)

  9. #7
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Open subwindow

    Cool, that's it.

    I just had to additionally specify

    w->setWindowFlags(Qt::Window);

    To summarise, I use the following code now:

    Qt Code:
    1. void MainWindow::openSubWindow()
    2. {
    3. SubWindowWidget *w = new SubWindowWidget(0);
    4. w->setParent(this);
    5. w->setWindowFlags(Qt::Window);
    6. w->setAttribute(Qt::WA_DeleteOnClose);
    7. w->setAttribute(Qt::WA_ShowModal);
    8. w->show();
    9. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for all your help again!

    Problem solved, thread can be closed.

  10. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Open subwindow

    it's better to do like this
    Qt Code:
    1. void MainWindow::openSubWindow()
    2. {
    3. SubWindowWidget *w = new SubWindowWidget(this);
    4. w->setAttribute(Qt::WA_DeleteOnClose);
    5. w->setAttribute(Qt::WA_ShowModal);
    6. w->show();
    7. }
    To copy to clipboard, switch view to plain text mode 
    EDITED: you can also remove w->setAttribute(Qt::WA_DeleteOnClose); because since you pass a parent in SubWindowWidget it will be deleted when a parent is being deleted.
    Last edited by spirit; 14th May 2009 at 13:02.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  11. #9
    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: Open subwindow

    I'd do it like this:
    Qt Code:
    1. void MainWindow::openSubWindow()
    2. {
    3. QDialog dlg(this);
    4. QHBoxLayout *l = new QHBoxLayout(&dlg);
    5. SubWindowWidget *w = new SubWindowWidget;
    6. l->addWidget(w);
    7. dlg.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Open subwindow from parent window ctor
    By olidem in forum Qt Programming
    Replies: 11
    Last Post: 13th May 2009, 14:52
  2. cannot open a subwindow!
    By cbarmpar in forum Qt Programming
    Replies: 1
    Last Post: 22nd September 2008, 16:06
  3. QTextBrowser: Cannot open
    By veda in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2007, 12:05
  4. again Open Cascade + Qt 4.2.2 but detailed...
    By Shuchi Agrawal in forum Qt Programming
    Replies: 11
    Last Post: 1st February 2007, 07:03
  5. again Open Cascade + Qt 4.2.2 but detailed...
    By Shuchi Agrawal in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 06:50

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.