PDA

View Full Version : Resizing Mfc dialog with embeded QWinWidget



elizabeth.h1
21st August 2009, 16:17
Hello

I have an Mfc dialog with QWinWidget inside it.
When I resize my dialog I want my QWinWidget to automatically
be resized and repositioned as well. This is the code that creates the QWinWidget inside the mfc dialog :



int MyCDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate( lpCreateStruct ) == -1 )
return -1;
win=new QWinWidget( this->m_hWnd );
MyFrame * dialog=new MyFrame(win);
win->move(0,0);
win->show();
return 0;
}



MyFrame is derived from QFrame object. The QFrame object is made
with Qt designer. QFrame has assigned layout, which suppose to do geometrical managment of QFrame child widgets.

Here is the code that executes when I drag the resizing border of my dialog :


void MyCDailog::OnSize()
{
QObjectList list=win->children();
QFrame* p=(QFrame*) list.at(0);
p->resize(QSize(cx,cy));
}


When the dialog is resized I am calling the resize method of my frame
object, and I was expecting that after I do resize to the frame
,the frame should resize and repositon its child widgets according to
their size hint and size polices. But this is not happening, at least
not as it should. What I am doing wrong ?
Thanks

elizabeth.h1
22nd August 2009, 22:29
Now I added layout to my QWinWidget and it seems to work .Although I am not sure why.



int MyCDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate( lpCreateStruct ) == -1 )
return -1;
win=new QWinWidget( this->m_hWnd );
MyFrame * dialog=new MyFrame(win);
QVBoxLayout mylayout=new QVBoxLayout ;
mylayout->addWidget(dialog);
win->setLayout(mylayout);
win->move(0,0);
win->show();
return 0;
}


and in my OnSize handler :



void MyCDailog::OnSize(UINT nType,int cx,int cy)
{
win->resize(cx,cy);

}