How should I write this program?



  • [code]
    /*

    • File: BaseWidget.h
    • Author: Jacky
    • Created on 2014年04月28日 星期一, 下午6:26
      */

    #ifndef _BASEWIDGET_H
    #define _BASEWIDGET_H

    #include <windows.h>
    #include <d3d9.h>
    #include <QWidget.h>
    #include <QtGui/QResizeEvent>
    #include <QtWidgets/QMainWindow.h>
    #include <QtWidgets/QStatusBar.h>
    #include <QtGui/QVector2D.h>
    #include <QtGui/QVector3D.h>
    #include <QtGui/QVector4D.h>
    #include "ui_BaseWidget.h"

    //#include "common.h"
    //#include "camera.h"

    class BaseWidget : public QWidget {
    Q_OBJECT
    public:
    // BT_DECLARE_ALIGNED_ALLOCATOR()

    BaseWidget(); 
    
    BaseWidget( QWidget *parent = 0, Qt::WindowFlags flags = 0 ) : QWidget( parent, flags )
    {
            setAttribute(Qt::WA_PaintOnScreen);
            setAttribute(Qt::WA_NoSystemBackground);           
    }
    virtual ~BaseWidget();
     
    virtual void setVisible(bool visible)
    {
            if(visible)
            {
                    QWidget::setVisible(visible);
                    //initialize();
            }
            else
            {
                    //uninitialize();
                    QWidget::setVisible(visible);
            }
    } 
    

    private:
    Ui::BaseWidget widget;
    };

    #endif /* _BASEWIDGET_H */

    /*

    • File: myDX9Widget.h
    • Author: Jacky
    • Created on 2014年04月28日 星期一, 下午6:34
      */

    #ifndef MYDX9WIDGET_H
    #define MYDX9WIDGET_H

    #include "BaseWidget.h"
    #include "ogrerecast/Samples/include/BaseApplication.h"

    using namespace Ogre;

    class myDX9Widget : public BaseWidget {
    public:
    #ifdef QWIDGET_H
    myDX9Widget( QWidget *parent = 0, Qt::WindowFlags flags = 0);
    #else
    myDX9Widget();
    #endif

    virtual ~myDX9Widget(); 
    

    private:

    SceneManager                                                 *m_SceneMgr;
    

    private:

    };

    #endif /* MYDX9WIDGET_H */

    /*

    • File: MainWindow.h
    • Author: Jacky
    • Created on 2014年04月28日 星期一, 下午6:22
      */

    #ifndef _MAINWINDOW_H
    #define _MAINWINDOW_H

    #include "ui_MainWindow.h"
    #include "myDX9Widget.h"

    class MainWindow : public QMainWindow {
    Q_OBJECT
    public:
    MainWindow(myDX9Widget *awidget);
    virtual ~MainWindow();
    private:
    Ui::MainWindow widget;
    };

    #endif /* _MAINWINDOW_H */

    /*

    • File: MainWindow.cpp
    • Author: Jacky
    • Created on 2014年04月28日 星期一, 下午6:22
      */

    #include "./MainWindow.h"

    MainWindow::MainWindow(myDX9Widget *aWidget) {
    widget.setupUi(this);
    //widget = aWidget;
    }

    MainWindow::~MainWindow() {
    }
    [/code]

    I create a MainWindow, in the window, I'd like to create a child window, so I pass in a
    QWidget derived object, called myDX9Widget. How can I attach myDX9Widget to MainWindow?
    Thanks
    Jack



  • Hi,

    Hope you had seen the documentation first.
    Actually QMainWindow contains several parts like DockWidget, Central Widget, Toolbar etc...
    Now if you want to add your child widget as centeral then you can use
    void setCentralWidget ( QWidget * widget ) function else you have option to add your widget at four dock position like top, bottom, left, & right for that you will need to create something like that,

    @QDockWidget *dockWidget = new QDockWidget(tr("Dock Widget"), this);
    dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    dockWidget->setWidget(dockWidgetContents);
    addDockWidget(Qt::LeftDockWidgetArea, dockWidget);@

    Hope I answer your question .....
    If your looking for something different than that then explain your problem in more specific words so we can help you in that way......

    Thanks
    Prashant Moglaikar

    qxoz: "@" added



  • Yep, I am just right looking into this stuff.
    I have been thinking about it in a convoluted way.
    Thanks for loosening it up.
    Jack


Log in to reply
 

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