Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. class inheriting directly from QMdiSubWindow?

class inheriting directly from QMdiSubWindow?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Shadowblitz16S Offline
    Shadowblitz16S Offline
    Shadowblitz16
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kenchan
      wrote on last edited by
      #2

      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...

      1 Reply Last reply
      1
      • Shadowblitz16S Offline
        Shadowblitz16S Offline
        Shadowblitz16
        wrote on last edited by Shadowblitz16
        #3

        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.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kenchan
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • Shadowblitz16S Offline
            Shadowblitz16S Offline
            Shadowblitz16
            wrote on last edited by
            #5

            they are both graphicviews that are on a widget

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kenchan
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • Shadowblitz16S Offline
                Shadowblitz16S Offline
                Shadowblitz16
                wrote on last edited by
                #7

                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();
                }
                
                
                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kenchan
                  wrote on last edited by kenchan
                  #8

                  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.

                  1 Reply Last reply
                  2
                  • Shadowblitz16S Offline
                    Shadowblitz16S Offline
                    Shadowblitz16
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • Shadowblitz16S Offline
                      Shadowblitz16S Offline
                      Shadowblitz16
                      wrote on last edited by
                      #10

                      @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();
                      }
                      
                      
                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved