Results 1 to 5 of 5

Thread: Positioning Child Windows on a QMainWindow

  1. #1
    Join Date
    Jan 2008
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Positioning Child Windows on a QMainWindow

    I've created a QMainWindow upon which I want to be able to place 1 or 2 QDialog based child windows from a choice of 5. All the child windows are the same size and the workspace is slightly deeper than a child window and slightly wider than a pair of child windows.

    When I activate the first child window, it appears in the upper left of the workspace. If I activate a second child window it appear next to the first. However, if I close the first child, the second still appears as if the first window was still there.

    Is there any setting in QWorkspace, (or in the destructor of the children) that will always place a child in the left most position if the workspace is empty? The workspace seems to have memory of what happened previously.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Positioning Child Windows on a QMainWindow

    Firstly, you should be using QMdiArea not QWorkspace, which as the friendly docs say:
    The QWorkspace widget provides a workspace window that can be used in an MDI application.

    This class is deprecated. Use QMdiArea instead.
    MDI child windows stay where the user places them (or leaves them in this case) just as the user would expect. Windows jumping around without user command is bad karma in my book. You could, of course, move the window yourself in response to some iAmClosing() signal you arrange.

  3. #3
    Join Date
    Jan 2008
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Positioning Child Windows on a QMainWindow

    Thanks Chris. This looks like the right way to go. However, my implementation has some serious faults with it. Code is:

    void MainWindow::newQC()
    {
    QC *qch = createQC();

    qch->showNormal();
    }

    QC *MainWindow::createQC()
    {
    QC *qc = new QC;

    mdiarea->addSubWindow( qc);
    qc->setFixedSize( 470,400);

    return qc;
    }

    When I initiate the subwindow with a menubar command, I get a minimized subwindow. Maximizing displays the subwindow filling the entire mdiarea. Clicking the window size button reduces the subwindow size to the 470X400 that was set in QtDesigner. However, the base color of the QDialog subwindow is the default color, not that set by QtDesigner. However, buttons, textEdits and LineEdits display correctly. I'm missing something important.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Positioning Child Windows on a QMainWindow

    Quote Originally Posted by GTBuilder View Post
    Thanks Chris. This looks like the right way to go. However, my implementation has some serious faults with it. Code is:
    Qt Code:
    1. void MainWindow::newQC()
    2. {
    3. QC *qch = createQC();
    4.  
    5. qch->showNormal();
    6. }
    To copy to clipboard, switch view to plain text mode 
    As mentioned in the QWidget::showNormal() docs the function only affects windows, i.e. unparented widgets. Your QC object is a child of the QMdiSubWindow. I see no need to call this, it will be shown by default when added.

    When I initiate the subwindow with a menubar command, I get a minimized subwindow.
    No code, no ideas.
    Maximizing displays the subwindow filling the entire mdiarea.
    Correct operation.
    Clicking the window size button reduces the subwindow size to the 470X400 that was set in QtDesigner.
    You set that size in code not Designer. Seems reasonable enough that it would restore to its nominal size.
    However, the base color of the QDialog subwindow is the default color, not that set by QtDesigner. However, buttons, textEdits and LineEdits display correctly. I'm missing something important.
    I have no idea what a "QDialog subwindow" is. If you mean the "empty" area of the QMdiArea then you should be able to simply call setBackground() with the relevant brush (it doesn't use a style sheet).

  5. #5
    Join Date
    Jan 2008
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Positioning Child Windows on a QMainWindow

    OK, let's go back to the beginning. I created a QC.ui file using QtDesigner to specify a QDialog widget with some pushbuttons, textEdits, etc. I then created the main.cpp, QC.cpp and QC.h files to control the widget that appears on the Windows desktop. I then created 4 additional programs all based upon the some QC.ui file. As my overall application only requires that 2 widgets appear at any one time I created an overall QMainWindow to manage the QDialog widgets, displaying them in a QWorkspace on the QMainWindow. The code:

    void MainWindow::newQC()
    {
    QC *qch = createQC();
    qch->show();
    }

    QC *MainWindow::createQC()
    {
    QC *qc = new QC;

    workspace->addWindow( qc);

    return qc;
    }


    where newQC() is a slot activated by a menubar QAction.

    Etc for the other 4 modules.


    The QC object appears in the workspace exactly as it appears on the desktop. I don't have to do anything in the QMainWindow code to contol it's size or color. The only issue, as discussed in my original post is that I can't control where the widgets appear in the workspace. If QmdiArea can't do likewise, then QWorkspace may not be deprecated at all.

Similar Threads

  1. Replies: 0
    Last Post: 22nd September 2011, 11:31
  2. QMainWindow as a child of QMainWindow
    By Elder Orb in forum Qt Programming
    Replies: 8
    Last Post: 12th February 2011, 22:31
  3. Replies: 0
    Last Post: 17th November 2010, 18:07
  4. positioning sub windows in an mdiarea
    By eric_vi in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2009, 00:08
  5. QMainWindow child of a QDialog
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2008, 08:16

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
  •  
Qt is a trademark of The Qt Company.