Solved Reloading certain widgets present on stacked widgets after pressing buttons
-
There is stacked Widget named "mainApp" which has 3 widgets promoted to different custom widgets
page1->readData
page2->writeData
page3->viewData
On above data the names on left side is page name and names on right side is "custom Widget"I have certain buttons namely read , write and view
All the information are fetched from database
this is just exampleRespective buttons are connected with respective widgets
So question is when going from one widget to another widget I want to reload whole page
void mainwindow::on_read_clicked(){ ui->mainApp->setCurrentIndex(0); // I guess something should be added here } void mainwindow::on_write_clicked(){ ui->mainApp->setCurrentIndex(1); } void mainwindow::on_view_clicked(){ ui->mainApp->setCurrentIndex(2); }
So How to reload that specific widget when buttons are clicked;
-
@Thank-You said in Reloading certain widgets present on stacked widgets after pressing buttons:
Is there any method to reload whole widget??
If I understood you correctly you want to add data from database to your widget which was added to the database previously in another page, right? So, you do not reload the widget, you add data to it. Also, you should mention what widget that is and how you fill it with data. There is no magic, you have to read the database and add the data to the widget.
If you want to do it properly then please read https://doc.qt.io/qt-5/model-view-programming.html and check the examples.
-
@Thank-You said in Reloading certain widgets present on stacked widgets after pressing buttons:
I want to reload whole page
What does "reload" mean here?
What exactly do you want to reload? -
@jsulm I want to reload whole ui
From example
I want to reload whole readData widget -
@jsulm Can I reload some functions only??
-
@Thank-You I still don't understand what you want to reload and why.
Why is it not enough to simply show the page?
"Can I reload some functions only??" - what functions? Can you please explain your use case? -
I have a database in folder.
in writeData we can add new user
and in viewData we can view added userSo main problem is
when I add new user from writeData and go to viewData
the new user is not shown at that time.
But when I reopen the application that user is shownSo I guess you will understand "What I want to do here"??
If you did not understand please ask me one more time
-
@Thank-You You should take a look at https://doc.qt.io/qt-5/model-view-programming.html
If you don't want to use the above you can still load the data (not the ui!) in https://doc.qt.io/qt-5/qwidget.html#showEvent of your pages.
-
@jsulm I tried to use
ui->readData->repaint();
ui->readData->update(0,0,ui->readData->width() , ui->readData->height());It didn't work
Is it wrong method -
@Thank-You said in Reloading certain widgets present on stacked widgets after pressing buttons:
It didn't work
Of course it did not work! How should it? repaint/update simply retriggers a paint, it does not magically read your database.
You need to read the data from the database and add it to your ui, not just repainting.
So, fir example if you show second page and need to add data which was added on first page dovoid mainwindow::on_view_clicked(){ // Read the data from the database and add it to the widgets on second page ui->mainApp->setCurrentIndex(2); }
-
@jsulm Is there any method to reload whole widget??
Like as of calling constructor -
@Thank-You said in Reloading certain widgets present on stacked widgets after pressing buttons:
Is there any method to reload whole widget??
If I understood you correctly you want to add data from database to your widget which was added to the database previously in another page, right? So, you do not reload the widget, you add data to it. Also, you should mention what widget that is and how you fill it with data. There is no magic, you have to read the database and add the data to the widget.
If you want to do it properly then please read https://doc.qt.io/qt-5/model-view-programming.html and check the examples.
-
@Thank-You said in Reloading certain widgets present on stacked widgets after pressing buttons:
Is there any method to reload whole widget??
Like as of calling constructormove everything you do in the constructor into its own function, call that function from the constructor and every time you want to "reload" your page
-