stackedwidget for different class which they have their own .cpp , .h, and .ui
-
page1 is a local variable used in Page_1.cpp, you can't access it like that in Page_stackedWidget.cpp (and don't try or you are going to write pretty ugly code).
Shouldn't you be doing something like:
Page_1 *page_1 = new Page_1; stackedWidget->addWidget(page_1);
?
-
The thing is there were going to be multiple pages and I wanted to stack the widgets in a different file. I was able to achieve that with Page_stackedWidget.ui. However, I would like it so when I press a button that is in page 1 it takes me to page 2. This is what I have for Page_stackedWidget.cpp
#include "dialog.h" #include "ui_dialog.h" Page_stackedWidget::Page_stackedWidget(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) } ui->setupUi(this); connect(_signin->nextButton, SIGNAL(clicked()),this,SLOT(goToPage2())); } void Dialog::goToPage2() { ui->stackedWidget->setCurrentIndex(1); }
However, the "nextButton" I created on the .ui file for Page1. I have looked for forums and i have found some similar to my problem but the difference is that their button is created on this file. http://stackoverflow.com/questions/9694474/manipulating-qt-ui-with-different-source-files.
-
Hi
If I understand you correctly,
you can maybe use the promote feature.Say you have
UI A,B,C
B and C contains widgets like buttons etc.on A you put a stacked widget
and on page 1 it has all of B, and on page 2, it has all of C
and they still live in their own UI files. ?That you can do via promote. In short you place a QWidget in the stacked paged and it will be replaced
by all widget from an UI file. When you run the program.
Note: select QWidget as parent, not dialog when you create B,C.Please see
https://forum.qt.io/topic/59373/solved-recommended-approach-for-inline-modal/13If its not what you mean, then sorry :)
-
@mrjj I did put a widget on the stackedWidget. Even though it is a QDialog, I created a widget inside of it. I was able to call the files and add them into the stackwidget. My question now is how do I call a qpushbutton created from Page1?
-
@marlenet15
well , say the place holder widget is called Wid2, (the one you promoted)
then you can access any widget using the normalui->Wid2->SomeButton
its being created in the ui_xx file for the UI that contains the promoted widgets.
-
Each widget should be self-contained so what exactly do you want to do with that button from another widget in your stack ?
-
I want to press that button to go the next page that is in the stack
-
In that case and from a design point of view, does it really belong to a widget inside the stack ?
-
Yes it does.
-
Then add a signal to that widget that will forward the button clicked signal. Something like nextPageRequested. That will be cleaner and easier to understand when you read the code.
-
I know but how am I supposed to access that widget when it is in another class?
connect(Page1->nextButton, SIGNAL(clicked()),this,SLOT(goToPage2()));
Where Page1 is the widget that contains the button "nextButton" and when you press it will go to Page2
-
That's what I wrote: you don't access the button, you only connect Page1.
Are you trying to re-implement QWizard ?
-
Yes but I do not want to use QWizard since I don't want it in that style. The only similarity is that I can go from one page to another.