sepideh
sepideh

Reputation: 9

How to have many layouts in one window?

I want to have some sequential actions; for example press a QPushButton and then delete the layout that is running and run another layout in the "SAME WINDOW"

In fact, I don't know what exactly layouts and widgets are! Are they an object? an instance of object or what?

I found the bellow code in the Internet, I don't know how to change it to make it useful for me

#include <QApplication> 
#include <QPushButton> 
int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    QWidget *window = new Qwidget; 
    QPushButton *button1 = new QPushButton("One"); 
    QPushButton *button2 = new QPushButton("Two"); QPushButton *button3 = new QpushButton("Three");
    QHBoxLayout *layout = new QHBoxLayout; 
    layout->addWidget(button1);
    layout->addWidget(button2);
    layout->addWidget(button3);
    window->setLayout(layout);
    window->show();
    return app.exec(); 
}

Upvotes: 0

Views: 54

Answers (1)

SionHughes
SionHughes

Reputation: 148

A better way than deleting layout and setting a new one would be to use a QStackedWidget (docs) and the concept of pages. Using QStackedWidget you can show and hide pages as you wish.

Upvotes: 1

Related Questions