Unsolved How to use QStackedwidget without using designer form ?Also should be capable of navigating between pages when button is clicked.
-
int main(int argc, char *argv[])
{
QApplication a(argc, argv);// create main window QMainWindow *mainwindow = new QMainWindow() ; // create main widget QWidget *mainwidget = new QWidget() ; // create button QPushButton *button = new QPushButton("Button") ; button->setFixedWidth(200) ; // create stacked widget and add button QStackedWidget *stack = new QStackedWidget() ; stack->addWidget(button) ; stack->setCurrentIndex(0); // create layout QHBoxLayout *mainlayout = new QHBoxLayout() ; mainlayout->setMargin(5) ; mainlayout->addWidget(stack) ; mainwidget->setLayout(mainlayout) ; mainwindow->setCentralWidget(mainwidget) ; mainwindow->show(); return a.exec();
}
-
Hi and welcome to the forums
Your code is almost as expected, except you add the button as the actual Page.
It's more likely you want a QWidget with a layout and then insert buttons to that layout.
ELse BUtton is the page which is kinda odd :)
So its much like you do with the mainwidget.Can I ask why you don't want to use UI(designer form class ) file?
You can both use UI file and code and actually, UI file is just code that is run in the
setupUI() function. -
Reason i am not using Qt designer is, i am developing a application in which one page is having 400 radio button it is easy for me to develop a logic to handle 400 radio buttons when i do not use Qt designer.
So please help me to navigate between pages using QStackedWidget when button is clicked. -
@Mahendra-HD said in How to use QStackedwidget without using designer form ?Also should be capable of navigating between pages when button is clicked.:
So please help me to navigate between pages using QStackedWidget when button is clicked
See http://doc.qt.io/qt-5/qstackedwidget.html#currentIndex-prop