添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
踢足球的香蕉  ·  用MATLAB ...·  1小时前    · 
腹黑的鼠标  ·  matlab ...·  1小时前    · 
高兴的板栗  ·  编写 SELinux 政策  |  ...·  3 月前    · 
正直的桔子  ·  市中简讯 | ...·  8 月前    · 
安静的豆浆  ·  在SQL ...·  9 月前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am new to Qt and am have to make a GUI having multiple windows for this I found QStackedWidget class using Qt designer tools.

I added QStackedWidget using add new->Qt designer form class->Qstackwidget

after that I created an object of this class in my main window

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include<stackedwidget.h>
namespace Ui { class MainWindow; }
class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
private slots:
    void on_pushButton_clicked();
private:
    Ui::MainWindow *ui;
    StackedWidget *stk; };
#endif // MAINWINDOW_H

then i tried to display StackedWidget by:

#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    ui->setupUi(this);
MainWindow::~MainWindow()
    delete ui;
void MainWindow::on_pushButton_clicked()
    stk = new StackedWidget(this);
    stk->show();

But stackwidget is not opening .

Can someone tell me what am I doing wrong and how to implement QStackedWidget GUI using designer tools?

Change stk = new StackedWidget(this); stk->show(); to stk = new StackedWidget(this); centralWidget()->layout()->addWidget(stk); – eyllanesc Aug 17, 2017 at 5:21 i want to add multiple pages in it but right now i am not even able to understand how to display it – vasu gupta Aug 17, 2017 at 5:23 First you have to add the QStackedWidget to your MainWindow, with the code that shows what you are doing, then add the other widgets to your QStackedWidget. – eyllanesc Aug 17, 2017 at 5:25

The QStackedWidget class provides a stack of widgets where only one widget is visible at a time.

You are new to Qt so I suggest you to using Qt Designer: Image Example

You can drag&drop StackedWidget to your form, customize it then use arrows to go to the next page and work on it too.

StackedWidget is like a vector you can access them via indexes.

ui->stackedWidget->setCurrentIndex(1);
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.