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