Solved Implementing multiple Screens
-
Hello, everyone, I want to implement multiple screen functionality.
For example, I have a screen 1 with a set of widgets similarly, screen 2 and 3, and so on. I have created a project which has QMainWindow widget with how can I replace the contents of my screen with the existing elements on the QMainWindow.
Is there a specific approach for the same? Or what is the best way to implement the above functionality. -
@Kira Sounds like https://doc.qt.io/qt-5/qstackedwidget.html is what you need
-
@jsulm : Thanks for reply without stack widget.
Can i replace the central widget with new widgets every now and then ? -
@Kira said in Implementing multiple Screens:
Can i replace the central widget with new widgets every now and then ?
You can, or you use the central widget as parent for the other widgets you want to put as "screens". So, as parent for your "screens".
-
@jsulm :
Thanks for the reply.
Just for clarification, please verify the steps.
Create multiple form file using inheriting Qwidget.
Set the central widget to one of the widget form files.
If the above approach is correct can you please provide an example
because I am getting a lot of errors. -
@Kira said in Implementing multiple Screens:
because I am getting a lot of errors.
Please post the errors
-
@jsulm : Sorry for the delay in reply.
I have created a git repo of the example, please have a look on the below link: https://github.com/HackersSpirit/SwitchingWidget
I am facing the following issue:
When I set the central layout to widget1, it works
Setting the centralLayout to widget2 also works
Resetting the centralLayout to widget1 causes the application to crash. -
@Kira See https://doc.qt.io/qt-5/qmainwindow.html#setCentralWidget
"Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time."I think if you set second widget as central widget the first one is automatically deleted as main window has the ownership. And if you then again try to set the first one it do4es not exist anymore and the pointer is invalid, hence the crash.
You can change your code and only create your widgets when you want to set them as central widget. -
@jsulm :Thanks for the clarification. I was looking at this as an approach to implement the functionality of replacing the widgets on a fly. But if this the issue, I think this approach cannot be applied.
I need to implement the below functionality:
elow functionality,
If I click on the project the contents on the right-hand side get refreshed
If I click on an example, I get a new set of widgets. -
@Kira This is exactly what https://doc.qt.io/qt-5/qstackedwidget.html is doing.
Why don't you want to use it? -
@jsulm :
Thanks for the clarity and patience.
I went through the examples, and Stacked Widget is what I needed
I was trying to reimplement existing functionality.
Patient and helping people is what I love most about the forum.
Thanks once again.