How to create a Multi widgets Qt application - c++

Is it possible to develop an application with a multitude of interfaces (widgets), where each widget has its own .cpp and .h file? If so, can you suggest a way to do that?
I am aware of the stacked widget way but this method doesn't allow me to separate the code of each page from the others.
I need to have the general structure of my application to be similar to an android application developed in Eclipse.

You can create widgets separately, then, dynamically construct QStackedWidget and add widgets to it using addWidget method
PS. you can also use widget promotion, to have QStackedWidget be created by QtDesigner and filled with your widgets
http://doc.qt.digia.com/stable/designer-using-custom-widgets.html

Related

Qt QWidget multiple instances

We are multiple people working on one Qt app. I for one am implementing a library, which will be instanciated in multiple other parts of the app. This library has a display class+form along with it.
Until now I had simply created one single instance of the library, running on a dummy, and passed debug data to one instance of the display+form, and worked like that.
But now that core debugging is finished, goal is to have everything instantiable - not just the core library code, but also the form itself, and embed that form into other displays. Each caller/user would be reponsible for passing output data of the core library instance they are using to an instance of the form. Each instance of the form would separately display the information generated by a specific library instance, possibly with different display options - they are all independent.
Similarly, it is possible to enter values in my display. Goal is to be able to enter different values in different displays instantiated accross the app, and sending those to specific instances (caller's responsiblity).
Question is of course : how to do that ? Internet talks about promoting, but I still don't see anywhere in Qt Designer where to include so-called promoted objects in other objects.
TL;DR : : I want some existing form to appear in the menu on the left in Qt Designer to be able to instantiate it multiple times in other forms. How to do this ?
Thanks in advance for the help !
Charles
You can promote any QWidget to your control from within Qt Designer. Add a QWidget, right-click and promote.
Ideally, you should create a designer plugin for your control, make the relevant properties designable, and build the plugin as well as the library. That way you'll be able to drag your control from the palette, and it will behave like the real thing.
Qt QWidget multiple instances
You answered yourself. Qt Creator: "File->New->Qt->Qt Designer Form Class" with QWidget as a base class will suit you. Then you can promote a simple QWidget in the UI into this custom widget, to create an instance. Each instance will manage its own UI.

Qt: How can I use my widgets created with code in the *.ui file

I have a project in Qt made with the QWizard and QWizardPage classes. There are two ways to create a widget i.e: a Label:
One is going to the *.ui file and search the element and put it where you want (visual way). Then you can access it on your code with ui->nameOfLabel.
The other one is going to your code and creating it like QLabel codedLabel;
Actually I'm using the second way (it's easier for me to create, show and use) but my question is: Is there any way that I can see my label codedLabel on the *.ui file?
I would like to move it to a space in the screen and in that case, it would be much easier for me to be able to do it through the visual way (but having the label created in the code instead of the ui).
Thank you so much.
Widgets created at runtime from your source code and being added to a widget as child CANNOT be seen in Qt Designer when you edit the .ui file of the widget they will be added to.
However, there could be an alternative (reading what you are trying to achieve: having some child widgets being present or not based on the context):
Create the widget from the .ui within Qt Designer and hide it (QWidget::hide()) or even remove it (QLayout::removeWidget()) programmatically if not needed at runtime.
If the real reason why you want to see it is because you want to "move it to a space in the screen and in that case, it would be much easier for me to be able to do it through the visual way". Then I recommend that you simply create an empty QWidget (or QLayout) in Qt Designer (graphically: easy to place where you want to) and later (programmatically) add your QLabel to it (rather than adding it to the main top-level widget): then, it goes in the place you determined from Qt Designer tool.
You should not need any complex code to programmatically display your QLabel in a specific place, just choose the right parent to have it be displayed in the right place!

Creating tabbed document interfaces in Qt Designer?

I am trying to write a program that will use a tabbed document interface (TDI) like seen in Notepad++ or most web browsers. I know how to build GUIs using Qt Designer, and code in Qt C++ (after a few days of playing around).
I have created an example of what each page widget will look like using Designer, and now I want to add the ability to create and testroy tabs at runtime, each containing a unique instance of the page widget. However, I have no idea how to do this without adding a class that extends QWidget, and building the page widget with code. I could go down this route, but I'm sure there must be a better way of creating a TDI; but I can't find any tutorials or examples of how to do this.
Does anyone have any suggestions?
For creating tab interfaces you should look into QTabWidget.
It is a container widget included in Qt Designer which automatically handles operations on tabs. It has several build in methods for manipulating its tabs and theirs contents.
Each page of QTabWidget is handled separately and can have different layouts and functionality.
If you want to include several different objects to one page assign a layout to it and then assign the objects to the layout.

Custom Layout in Qt Designer

Is there anyway that we can have Custom Layouts e.g. as defined at
https://doc.qt.io/archives/qt-4.7/examples-layouts.html
inside the Qt Designer ?
What would be the process to add such custom layouts in the Qt Designer? Can anyone guide about the steps involved for such custom enhancement in Qt Designer.
You can't create custom layout right inside QtDesigner. Instead you can write your layout as a plugin for QtDesigner. After this you can open QtDesigner and just drop your own layout to the form as any other widget in the Qt collection.
See this quide to find out how to write your own plugin for Qt. It's not so difficult.

Extract a portion of a Qt .ui file into its own .ui file

We have a designer creating a user interface for an application. The main window has several QStackedWidgets used for in place panel switching. What I'd like to be able to do is extract each individual panel that makes up each page of the QStackedWidget into it its own .ui file.
Is there an easy way to accomplish this from within Qt Designer, or are there any other tools to help accomplish this task short of redesigning all of the panels in their own .ui files?
You can cut/paste each panel into a blank QWidget (created with File > New), and save these widgets in their own .ui file.
When you copy a widget(lets call it widgetA) that contains other widgets(calling them miniWidgets) then the miniWidgets should still be layed out. WidgetA still needs a relayout and in that case its very easy to add a layout since you can practically use any layout you want (i suggest vertical or horizontal). Just right click on the widget containing widgetA then select Layout->horizontal Layout and that should do the trick.
If there is more than one widget than needs relayout then you are not copying the panel correctly and should copy one that englobes more of the panel.