Embedding cocos2d In the QT window (1)

Source: Internet
Author: User
cocos2dx\platform\qt\CCEGLView_qt.cpp
 
bool CCEGLView::Create(int iWidth, int iHeight)

It contains how to use qglwidget to create a form.

Or create the glwidget first, and then use

bool CCEGLView::SetWindow(GLWidget* window)
To create a window.

Add a qwidget to export controls.

cocos2dx\platform\qt\CCEGLView_qt.h:

public:
    QWidget *widget;

Cocos2dx \ platform \ QT \ cceglview_qt.cpp:

bool CCEGLView::Create(int iWidth, int iHeight)
{
    widget = new QWidget;
    widget->setAttribute(Qt::WA_PaintOnScreen);
    widget->setFixedSize(iWidth, iHeight);
    m_window = new GLWidget(iWidth,iHeight, CCDirector::sharedDirector(), widget);
 
    m_window->setMouseMoveFunc(&cocos2d::mouseMove);
    m_window->setMousePressFunc(&cocos2d::mousePress);
    m_window->setMouseReleaseFunc(&cocos2d::mouseRelease);
 
    m_window->setWindowFlags(m_window->windowFlags()& ~Qt::WindowMaximizeButtonHint);
    m_window->setFixedSize(iWidth, iHeight);
 
    widget->show();
 
    m_bIsSubWindow = true;
 
    bIsInit = true;
    s_pMainWindow = this;
 
    m_sSizeInPoint.width = iWidth;
    m_sSizeInPoint.height = iHeight;
    m_bOrientationInitVertical = (CCDeviceOrientationPortrait == m_eInitOrientation
                || kCCDeviceOrientationPortraitUpsideDown == m_eInitOrientation) ? true : false;
 
return true;
}

Recompile libcocos2d

Helloworld modify appdelegate. cpp
bool AppDelegate::initInstance() 

#if (CC_TARGET_PLATFORM == CC_PLATFORM_QT)
        CCEGLView * pMainWnd = new CCEGLView();
        CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(480, 320));
// Add. This widget cannot retain the interface externally. For example, declare window as a public variable and access it from the outside. The specific reason is unknown.
        QWidget *window = new QWidget();
        window->setAttribute(Qt::WA_DeleteOnClose);
        QHBoxLayout *layout = new QHBoxLayout(window);
        layout->addWidget(pMainWnd->widget);
        window->show();
#endif

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.