class inheriting directly from QMdiSubWindow?



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

    I was following the tutorial here: http://sys-exit.blogspot.com/2013/02/qt-menu-mdi-child-window-example.html
    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. http://imgur.com/a/pe5Qu

    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 https://forum.qt.io/topic/78515/mdi-window-createdibsection-failed
    also yes.

    anyways heres the code

    mainwindow.h

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

    screeneditorform.h

    #ifndef SCREENEDITORFORM_H
    #define SCREENEDITORFORM_H
    
    #include <QWidget>
    #include <QMdiSubWindow>
    
    namespace Ui
    {
        class ScreenEditorForm;
    }
    
    class ScreenEditorForm : public QMdiSubWindow
    {
        Q_OBJECT
    
        public:
            explicit ScreenEditorForm(QWidget *parent = 0);
            ~ScreenEditorForm();
    
        private:
            Ui::ScreenEditorForm *ui;
    };
    
    #endif // SCREENEDITORFORM_H
    
    

    mainwindow.cpp

    #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->setupUi(this);
        ui->mdiArea->setBackground(QBrush(QColor(0,0,0,0)));
        //ui->dockWidget->setTitleBarWidget(new QWidget());
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_actionClose_triggered()
    {
        this->close();
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // ToolBar
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    void MainWindow::on_actionScreen_triggered()
    {
        ScreenEditorForm *screenEditor = new ScreenEditorForm(ui->mdiArea);
        screenEditor->setAttribute(Qt::WA_DeleteOnClose);
        screenEditor->setAttribute(Qt::WA_PaintOnScreen);
        screenEditor->show();
    }
    
    

    screeneditorform.cpp

    #include "screeneditorform.h"
    #include "ui_screeneditorform.h"
    
    ScreenEditorForm::ScreenEditorForm(QWidget *parent) : QMdiSubWindow(parent), ui(new Ui::ScreenEditorForm)
    {
        ui->setupUi(this);
        this->setParent(parent);
    }
    
    ScreenEditorForm::~ScreenEditorForm()
    {
        delete ui;
    }
    
    

    main.cpp

    #include <QApplication>
    #include <QFile>
    
    #include "mainwindow.h"
    
    int main(int argc, char *argv[])
    {
        //Q_INIT_RESOURCE(mdi);
    
        QApplication a(argc, argv);
        MainWindow w;
    
    
        // Load an application style
        QFile styleFile( ":/Resources/Styles/Style.qss");
        styleFile.open( QFile::ReadOnly );
    
        // Apply the loaded stylesheet
        QString style( styleFile.readAll() );
        a.setStyleSheet( style );
    
    
        w.setWindowState(Qt::WindowFullScreen);
        w.show();
    
        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;
    ui->mdiArea->addSubWindow(screenEditor);
    

    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..
    http://imgur.com/a/bHtxd

    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.
        screenForm->show();
    }
    
    

Log in to reply
 

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