Home > Mobile >  How to implement the window using a stack switch in QT
How to implement the window using a stack switch in QT

Time:11-03

I use a button to open the stack after an interface (1) the interface in the interface Settings button opens another interface (interface 2) would like to ask in interface (2) how to set up a new screen button to return to previous interface interface (1)
Void Laa... on_pushButton_clicked ()
{

}
What should be added the statement here,

CodePudding user response:

Is to use QStackedWidget? So use it setcurrentxxx method is ok

CodePudding user response:

Direct write one for you,,

The main. CPP:
 
# include "widget. H"
#include

Int main (int arg c, char * argv [])
{
QApplication a(argc, argv);
The Widget w;
Baron how ();

Return a.e xec ();
}

Widget. H:
 # # ifndef WIDGET_H 
# define WIDGET_H

#include
# include "mydialog. H"

The namespace Ui {
The class Widget;
}

The class Widget: public QWidget
{
Q_OBJECT

Public:
Explicit Widget (QWidget * parent=0);
~ the Widget ();


Public slots:
Void myslot ();
Void recvSignal ();

Private:
Ui: Ui widgets *;
DLG MyDialog *;
};

# endif//WIDGET_H

Widget. CPP:
 # include "widget. H" 
# include "ui_widget. H"
#include

Widgets: : widgets (QWidget * parent) :
QWidget (parent),
UI (new UI: : Widget)
{
The UI - & gt; SetupUi (this);
DLG=new MyDialog ();
The connect (UI - & gt; PushButton, SIGNAL (clicked (bool)), and this, SLOT (myslot ()));
The connect (DLG, SIGNAL (signalToParent ()), and this, SLOT (recvSignal ()));
}

Widgets: : ~ Widget ()
{
Delete the UI;
}

Void Widget: : myslot ()
{
DLG - & gt; Show ();
This - & gt; Hide ();
}

Void Widget: : recvSignal ()
{
This - & gt; Show ();
}

Mydialog. H:
 # # ifndef MYDIALOG_H 
# define MYDIALOG_H

#include

The namespace Ui {
The class MyDialog;
}

The class MyDialog: public QDialog
{
Q_OBJECT

Public:
Explicit MyDialog (QWidget * parent=0);
~ MyDialog ();

Public slots:
Void dlgSlot ();

Private:
Ui: : Ui MyDialog *;

QWidget * pParent;

Signals:
Void signalToParent ();
};

# endif//MYDIALOG_H

Mydialog. CPP:
 # include "mydialog. H" 
# include "ui_mydialog. H"

MyDialog: : MyDialog (QWidget * parent) :
QDialog (parent),
UI (new UI: : MyDialog)
{
The UI - & gt; SetupUi (this);
PParent=parent;
The connect (UI - & gt; PushButton, SIGNAL (clicked (bool)), and this, SLOT (dlgSlot ()));
}

MyDialog: : ~ MyDialog ()
{
Delete the UI;
}

Void MyDialog: : dlgSlot ()
{
Emit signalToParent ();
This - & gt; Hide ();
}


Widget. The UI with mydialog. UI file has a QPushbutton

Signals and slots mechanism is the essence of Qt, I need to understand the meaning of each parameter in the connect,

CodePudding user response:

Qt signals and slots to understand, or you write the code you also look not to understand

CodePudding user response:

Would solve the liao, I now can't window switch, forced out of the QAQ click button

CodePudding user response:

To achieve a yourself, actually not difficult also
  •  Tags:  
  • Qt
  • Related