Unsolved Understand multi-page GUI and multi-platform GUI
-
Hello everybody. I'm here to ask you something about GUIs. I have been using QT for about a year and I'm not a beginner at C++. First of all, I need to understand how to switch between different pages. I saw something about StackedWidget class but all the references that I found use a single .ui file with all the pages inside it and the .cpp file too.
At the moment, I'm using multiple .ui files and multiple .cpp, .h files (one C++ class per .ui file) because each .ui file need its different logic and I use the methods "show" and "hide" to switch between pages but there is a problem because when I switch from a page to another I see the desktop. So, could I use the StackedWidget approach to use different .cpp and .ui files? How could I do it? Furthermore, I'm using a RaspBerry PI, is this approach performing? I don't want to load every page in memory before to show it.
Secondly, if I would compile this application for mobile devices too, does the style of the buttons and of the other stuff changes automatically? -
@Giridhar first off, I'm wondering why you posted this in the QML forum, as it seems that your application uses Widgets, not QML.
Many (most?) apps feature a main window, and in the course of user interaction will open other windows as appropriate. Are you trying to hide the main window when other windows appear?
-
@mzimmers Because i din't find a correct section to post this.
By the way, I do not found anything that explain the difference between widgets and QML. Everybody say: "for desktop use widget, for mobile use QML", but which are the differences on creating the app, or on code?What I could say is I use the .ui file editor to put buttons and other stuff in the interface an sometimes I use c++ to change visibility or to remove/add new object depending on app's state. Is there a reference that explain everything good? How can I switch from a window to another rapidly?
-
@Giridhar this forum's OK but you'd probably get more viewers (and answers) if you posted in General and Desktop.
QML is a declarative way of creating UIs, while QWidgets are C++ classes. I too have heard that QML is preferred for mobile applications, but I'm not sure how big a difference it really makes. Personally, I'm more comfortable with QWidgets.
This page is a good start on explaining windows and displays within the Qt system.
-
Moved to "Mobile and Embedded" since it's the final targets.
-
On mobile devices there is only QML and no support for QWidgets. That is one of the major reasons between the two. QWidgets tries to use native APIs as much as possible. Windows and macOS have mostly the same widgets which are unified through QWidgets. QML is also more of a descriptive language similar to HTML and CSS. It is supposed to be more intuitive for designers.
Back to the original question. Using a QStackedWidget is the right approach. You can have separate ui-files for the separate pages of your stacked widget. I would then suggest that you create your QStackedWidget in C++. For each of the ui-files create a QWidget and the appropriate ui object. Then call
ui->setupUi(widget)
for each pair of ui and QWidget. Finally, add the widgets to the QStackedWidget as pages. -
@SimonSchroeder said in Understand multi-page GUI and multi-platform GUI:
On mobile devices there is only QML and no support for QWidgets
This is new to me. I'm quite sure QWidgets are available on mobile devices.
-
@jsulm said in Understand multi-page GUI and multi-platform GUI:
@SimonSchroeder said in Understand multi-page GUI and multi-platform GUI:
On mobile devices there is only QML and no support for QWidgets
This is new to me. I'm quite sure QWidgets are available on mobile devices.
Yes they are, not optimised for that use case but yes they are.
-
@SGaist said in Understand multi-page GUI and multi-platform GUI:
Yes they are, not optimised for that use case but yes they are.
Thanks for the clarification.
-
@SimonSchroeder said in Understand multi-page GUI and multi-platform GUI:
On mobile devices there is only QML and no support for QWidgets. That is one of the major reasons between the two. QWidgets tries to use native APIs as much as possible. Windows and macOS have mostly the same widgets which are unified through QWidgets. QML is also more of a descriptive language similar to HTML and CSS. It is supposed to be more intuitive for designers.
Back to the original question. Using a QStackedWidget is the right approach. You can have separate ui-files for the separate pages of your stacked widget. I would then suggest that you create your QStackedWidget in C++. For each of the ui-files create a QWidget and the appropriate ui object. Then call
ui->setupUi(widget)
for each pair of ui and QWidget. Finally, add the widgets to the QStackedWidget as pages.Ok, sI will develop a cross-platform application to be runnable on desktop, mobile and embedded, is it possible to implement this behaviour? I still didn't try it, I'm still understanding which is the best way to make an UI. For example, I did a web app using HTML/CSS/JS and using the Bootstrap framework. Why should I not use HTML + CSS + JS + WebKit and I should use QML?
I think that there are a lot of way to do the same thing and I get confused because I don't know how to choose the best one. I understood that QWidget are not the best approach for me 😁 -
I started to follow this playlist on youtube:
linkIt's really nice and I'm learning a lot
-
@Giridhar I've been watching ever since I saw your post. Agreed -- this is an excellent set of tutorials on QML.