c++ - A layout is set, but the QWidget still looks empty -


i'm working on basic school project, , can't figure how solve problem i'm encountering. please keep in mind i'm beginner in both c++ , qt, error might trivial (and i'd be!)

i'm trying use class developed recently: articleeditor. class inherits qwidget , meant small window can edit articles (a title , text) , save modifications. now, i've managed use class in basic way, creating instance of articleeditor , show in main.cpp file, i'm trying more tricky.

the point open articleeditor widget/window after picking file. i've achieved file picking part without issues, when i've chosen file, articleeditor widget opens and... totally empty. size set in setsize inside constructor taken account, widgets i'm setting , adding layout, in constructor, not present, nor visible.

here code, should understand situation :

articleeditor.cpp : enablesave() meant enable save button when edit 1 of 2 text fields, savearticle() method not important here.

articleeditor::articleeditor(article* article, qwidget *parent) :     qwidget(parent) {     title = new qlineedit();     title->setfixedwidth(180);     title->move(10,10);      text = new qtextedit();     text->setfixedsize(180,110);     text->move(10,45);      save = new qpushbutton();     save->settext("save");     save->setfixedwidth(80);     save->move(10,170);     save->setenabled(false);      title->settext(article->gettitle());     text->settext(article->gettext());      qobject::connect(save, signal(clicked()), this, slot(savearticle()));     qobject::connect(title, signal(textchanged(const qstring)), this, slot(enablesave()));     qobject::connect(text, signal(textchanged()), this, slot(enablesave()));      layout = new qvboxlayout;     layout->addwidget(title);     layout->addwidget(text);     layout->addwidget(save);      this->setfixedsize(200,200);     this->setlayout(layout); } 

articleeditor.h

class articleeditor : public qwidget     {         q_object     public:         explicit articleeditor(article* article, qwidget* parent);      private:         qlineedit* title;         qtextedit* text;         qpushbutton* save;         qvboxlayout* layout;         article* ressource;      public slots:         void savearticle();         void enablesave();      private slots:      }; 

after picking file (i'm not gonna give details because getting path working fine already), like:

articleeditor ae(&a, articlewidget); // calling constructor article i've fetched using path, , setting articlewidget (a private attribute) parent articlewidget->show(); // showing result 

here, articlewidget attribute of class, created articleeditor instance's parent widget.

i've tried setting directly layout parent widget (parent->setlayout(layout) instead of this->setlayout(layout), whenever this, content of widget shows, signals/slots connections not working anymore...

if explain me i'm doing wrong, i'd grateful.

edit : noticed after adding widgets layout, when try layout->isempty(), true return value...

the class fine, though, should use approach, koan recommended, gives lot more clarity code.

your problem set parent of articlewidget, didn't added layout it. istead of

articleeditor ae(&a, articlewidget); articlewidget->show(); // showing result (by way, if not using new, when create widget, shuold articlewidget.show();) 

do this:

articleeditor ae=new articleeditor(&a, articlewidget); //creating articleeditor ae articlewidget parent  qvboxlayout* articlewidgetlayout=new qvboxlayout(articlewidget); // creating layout in articlewidget articlewidgetlayout->addwidget(ae); //adding ae  articlewidget->show(); // showing result 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -