class inheriting directly from QMdiSubWindow?

  • can someone tell me how to make a class inheriting directly from QMdiSubWindow?

    I was following the tutorial here:
    but in that tutorial he says: "And now the most important thing. MyWidget is a graphical interface, therefore it cannot be a Mdi child window itself (if we tried it, Qt would cause display problems). We need to create a child window class separately which will include our graphical custom widget as its only widget. All GUI elements will be accessible within Qt Creator. So let's create a custom C++ class (it will not have any .ui file):"

    I don't want to have any unneeded classes and wanted to inherit directly for QMdiSubWindow however when I do the window bar is different and my widgets are overlapping the windowbar.

    I was wondering if there was a way to fix this?

  • I am not sure why you need to subclass QMdiSubWindow,? Usualy you don't need to
    Did you look at the mid example? here. This will show you how to use then and you can think about your customisation from there...

  • Thankyou kenchan I did come across this page however I could not read the code very well.
    I also couldn't tell what was necessary and what was just there for show.

    I would be glad to look at a stripped down version of it, that only implemented what was necessary.

  • so are those things (what are they anyway?) supposed to be inside the sub window?

  • they are both graphicviews that are on a widget

  • And the widget is supposed to be on the sub window??

    I think you had better post some code so people here can help with it.

  • I have recently edited it from this topic
    also yes.

    anyways heres the code


    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>
    namespace Ui {
    class MainWindow;
    class MainWindow : public QMainWindow
        explicit MainWindow(QWidget *parent = 0);
    private slots:
        void on_actionClose_triggered();
        void on_actionScreen_triggered();
        Ui::MainWindow *ui;
    #endif // MAINWINDOW_H


    #include <QWidget>
    #include <QMdiSubWindow>
    namespace Ui
        class ScreenEditorForm;
    class ScreenEditorForm : public QMdiSubWindow
            explicit ScreenEditorForm(QWidget *parent = 0);
            Ui::ScreenEditorForm *ui;


    #include <QtGui>
    #include <QBrush>
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "childwindow.h"
    MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainWindow)
        //ui->dockWidget->setTitleBarWidget(new QWidget());
        delete ui;
    void MainWindow::on_actionClose_triggered()
    // ToolBar
    void MainWindow::on_actionScreen_triggered()
        ScreenEditorForm *screenEditor = new ScreenEditorForm(ui->mdiArea);


    #include "screeneditorform.h"
    #include "ui_screeneditorform.h"
    ScreenEditorForm::ScreenEditorForm(QWidget *parent) : QMdiSubWindow(parent), ui(new Ui::ScreenEditorForm)
        delete ui;


    #include <QApplication>
    #include <QFile>
    #include "mainwindow.h"
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        MainWindow w;
        // Load an application style
        QFile styleFile( ":/Resources/Styles/Style.qss"); QFile::ReadOnly );
        // Apply the loaded stylesheet
        QString style( styleFile.readAll() );
        a.setStyleSheet( style );
        return a.exec();

  • Ok I kinda reproduced your app from your code. While not knowing the details of your widgets, could see the problem you mentioned when I added a text edit widget to your ScreenEditorForm. I put that a text edit widget in a layout in the ScreenEditorForm ui.

    When I added it to the main window mdi area like this..

    ChildWindow *screenEditor = new ChildWindow;

    it all seemed to work fine.

    I still don't understand why you need to subclass QMdiSubWindow. I think you can just make your custom edit widget or whatever and add it to the mdiArea with the addSubWindow(...) function and all you need to do is program your custom widget and not be concerned with the QMdiSubWndow details at all.

  • I wanted to subclass it because I don't want to have to create a child window class for every subwindow form I make.

    in the tutorial he just creates a new ChildWindow that creates the ScreenEditorForm inside of it.
    this is not what I want. I want to tell it what form to create. and I don't want to have to make a childwindow class for every form.

  • @kenchan

    I fix this issue and a few others..

    I just did this...

    void MainWindow::on_actionScreen_triggered()
        ScreenForm* screenForm = new ScreenForm;
        ui->mdiArea->addSubWindow(screenForm); //screenForm is the widget I want inside the subwindow.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.