c++ - Adding QFrame A to layout of QGroupBox B when QFrame is instantiated outside QGroupBox -


i encountered unwanted behavior when adding qframe in qvboxlayout of qgroupbox.

i have custom qframe class :

class customframe : public qframe {  } 

i have class customgb inherits qgroupbox method addframe supposed add type frame groupbox's layout

class customgb: public qgroupbox {     q_object      public:         customgb();         ~customgb();          void addcustomframe(customframe* aframe);     private:                qvboxlayout * _timelayout;      }  customgb::customgb() {     _timelayout=new qvboxlayout;     setlayout(_timelayout); }  customgb::addcustomframe(customframe * aframe) {     _timelayout->addwidget(aframe); } 

i want add new frame in groupbox.

i naturally call code (1st algo) :

  customframe * aframe = new customframe ();   cutomgbinstance.addcustomframe(aframe ); 

this results in frame not being added correctly in group box. it's added in top left corner. , calling code several times note add frames below each other every frame in exact same place. it's frames not in layout. unwanted behavior

however when call instead (2nd algo):

  customframe * aframe = new customframe ();   customgbinstance.layout()->addwidget(highlevelalertframe); 

it works fine. calling code several times result in several frame vertically aligned in groupbox. wantedbehavior

calling qvboxlayout::addwidget(qwidget *) method in scope instantiated frame gives me want. if call qvboxlayout::addwidget(qwidget *) method in different scope qwidget * passed through method example (like addcustomframe method) behaves weirdly.

i attached 2 pictures :

first 1 unwanted behavior (with 1st algo 3 times), second 1 want (and when calling 2nd algo 3 times).


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -