c++ - How to reference a form and change properties (height and width) from a function in Qt -
i'm starting qt trying migrate vb6. , i'm trying change size of window (ui form) function, before doing in action opens form this:
void f::on_actioncte_triggered() { frm_abm_ctes *w = new frm_abm_ctes(uf->mdiarea); w->setattribute(qt::wa_deleteonclose); w->setwindowstate(qt::windowmaximized); w->shownormal(); int hi = (this->height()/3) - (w->height()/3); int wi = (this->width()/3) - (w->width()/3); w->setgeometry(wi,hi,w->width(),w->height()); }
that works fine, idea if gonna lot of forms want call function changes geometry property of child form. like: function(parent,child) , use parent , child dynamic objects in function (as in visual basic or vs)
so did this:
void f::on_actioncte_triggered() { frm_abm_ctes *w = new frm_abm_ctes(uf->mdiarea); w->setattribute(qt::wa_deleteonclose); w->setwindowstate(qt::windowmaximized); w->shownormal(); forms(this,w) }
where forms
in *.h
file (which of course include) , goes this:
void forms(qmainwindow par, qmdisubwindow chi) { int hi = (par.height()/3) - (chi.height()/3); int wi = (par.width()/3) - (chi.width()/3); chi.setgeometry(wi,hi,chi.width(),chi.height()); }
and gives
error: not convert 'this' 'f* const' 'qmainwindow' forms(this,w); ^
i don't know best way approach problem. there way create public pointer , change property of form, or that?
thanks taking time read problem appreciated.
first of all, trying pass pointers method, you'll need adjust method take pointers. secondly, i'm not sure f (you haven't shown declaration), if it's qmainwindow subclass work fine so:
void forms(qmainwindow *par, qmdisubwindow *chi) { int hi = (par->height()/3) - (chi->height()/3); int wi = (par->width()/3) - (chi->width()/3); chi->setgeometry(wi, hi, chi->width(), chi->height()); }
Comments
Post a Comment