Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QMdiSubWindow in MdiArea is empty



  • Forgive me, i have only been using QT for a few hours. This is a super basic issue I am having but there is nothing in any of the documentation that is of any use.

    Essentially I have my QMainWindow that has an MdiArea set as the central widget. I want to open a QMdiSubWindow inside that mdiarea with a different QWidget displaying in there.

    This is what im doing:

    void MainWindow::open_subwindow()
    {
        QMdiSubWindow* sub_window = new QMdiSubWindow(ui->mdiArea);
        ui->mdiArea->addSubWindow(sub_window);
        sub_window->show();
    
        QOtherWidget* other_widget = new QOtherWidget(sub_window);
        sub_window->setWidget(other_widget);
        other_widget->show();
    }
    
    

    Super basic stuff, however the subwindow opens as the smallest possible size, and when I resize the window there is nothing drawing inside. If I omit the "setWidget" call and add a call to "setFixedSize()" then the widget will display, but the window can not be dragged around.

    The "QOtherWidget" is a default class setup from within QTCreator with a parent of QWidget and its layout just has a few random things thrown in there(text box and a button)

    Thanks in advanced.



  • @RetroZelda
    You show the MDI subwindow before it has any widget on it. I don't know if you have to "update" it if you later add a widget onto it. Try instead creating QOtherWidget first and setting it as the subwindow's widget before you show the subwindow.

    Then it sounds like your QOtherWidget does not have any size. When you say " and its layout just has ", make sure you really have set a layout on that widget (in Designer it must not show a "red no-entry sign" in the Object Browser).

    If you do want to set a fixed size (even if only to test) I think that must be set on QOtherWidget rather than on the QMdiSubWindow.



  • @JonB said in QMdiSubWindow in MdiArea is empty:

    @RetroZelda
    You show the MDI subwindow before it has any widget on it. I don't know if you have to "update" it if you later add a widget onto it. Try instead creating QOtherWidget first and setting it as the subwindow's widget before you show the subwindow.

    Then it sounds like your QOtherWidget does not have any size. When you say " and its layout just has ", make sure you really have set a layout on that widget (in Designer it must not show a "red no-entry sign" in the Object Browser).

    If you do want to set a fixed size (even if only to test) I think that must be set on QOtherWidget rather than on the QMdiSubWindow.

    Changing the ordering to show the subwindow to be after I set it as the subwindow gives the same results.

    What did end up working was calling SetFixedSize() on the widget instead of the subwindow, which is strange because I dont see any errors in the object browser so I wonder if theres an issue with my version of Qt Creator(4.14.1) that suppresses it, or that it is defaulting to the minimum or base size(which is defaulted to 0, 0) instead of the width and height set in its geometry. Fortunately this window can stay a fixed size, so its solved as far as im concerned :)

    Thanks a bunch



  • @RetroZelda
    I don't know why you have a problem, but since you say "so its solved as far as im concerned" I won't spend further time investigating. But I do just want to say this is not an issue to do with Qt Creator/Designer. That simply ends up generating C++ code (when uic is run during build) which calls Qt libraries to do the work.


Log in to reply