c++ - How to organize a system of parent and child windows that hide their parent. QT -



c++ - How to organize a system of parent and child windows that hide their parent. QT -

let’s have main window.

then when click button want kid window open , main windows hide. when close kid window want main windows reappear.

right i’m opening kid window doing:

s=new signupwindow(null,temp); s->show();

where s private pointer of main window.

when seek do:

s=new signupwindow(this,temp); s->show();

the s window doesn’t show up.

here signature of it’s constructor in it's header:

signupwindow (qwidget* parent=null, netflix *n=null);

can explain why set parent null in header? issues when seek play around it's parameters , errors like:

candidate expects 1 argument, 2 provided qt

thanks you're help -a tired college pupil learning qt

update next header main window:

class loginwindow : public qwidget { q_object public: loginwindow (qwidget* parent=null, netflix *n=null); public slots: void loggedin(); void newuser(); void quitpushed(); private: qpushbutton *quitbutton, *loginbutton, *newuserbutton; qlineedit *login;//this text area takes in loginid }; #endif

then there function initiated button click opens new windows:

void loginwindow::newuser() { s=new signupwindow(null,temp); s->show(); //this->hide(); }

how connect s loginwindow?

update 2 signupwindow.h:

class signupwindow : public qwidget { q_object public: signupwindow (qwidget* parent=null, netflix *n=null); public slots: private: };

signupwindow.cpp:

signupwindow::signupwindow (qwidget* parent, netflix *n) : qwidget (parent) { qvboxlayout *mainlayout = new qvboxlayout; //then add together things buttons , grouping boxes , etc no dialogs... }

i never made dialog signupwindow. added layouts , buttons etc.

when create signupwindow within loginwindow set this parent. in case able phone call parentwidget() within signupwindow , phone call hide(), when close signupwindow, phone call parentwidget() 1 time again , phone call show(). work when parent of signupwindow loginwindow.

in code parent null works when parent this.

but signupwindow should dialog or:

if signupwindow widget when set parent, signupwindow appears on parent, qdialog appears in separate window. if utilize qdialog subclass set parent , utilize solution, if utilize qwidget subclass set null parent , can't utilize parent-child relationship, should utilize signals , slots (catch signal signupwindow , show or hide loginwindow). create choice, pay attending qdialog more suitable task.

also suggest utilize closeevent sure can grab closing when user clicks on close button.

i wrote dialog , tested it, works fine:

header:

#ifndef dialog_h #define dialog_h #include <qdialog> #include <qcloseevent> namespace ui { class dialog; } class dialog : public qdialog { q_object public: explicit dialog(qwidget *parent = 0); ~dialog(); protected: void closeevent(qcloseevent *); private: ui::dialog *ui; }; #endif // dialog_h

cpp:

//constructor dialog::dialog(qwidget *parent) : qdialog(parent), ui(new ui::dialog) { ui->setupui(this); parentwidget()->hide(); } //closeevent void dialog::closeevent(qcloseevent *) { parentwidget()->show(); }

usage (inside mainwindow):

dialog *mdialog = new dialog(this); mdialog->show();

as can see set parent dialog appears separate windows , still can utilize parent-child relationship.

works want , easy, add together few lines of code.

c++ qt user-interface

Comments

Popular posts from this blog

c# - ASP.NET MVC Sequence contains no matching element -

java - Parsing XML, skip certain tags -

rest - How to invalidate user session on inactivity in a stateless server? -