multiple forms on MainWindow.ui using Qt creator - qt

how do I put the time, date and company logo on the top of all my Qt forms?
I don't want to redo this same code in all my classes.
I thought I could create 1 class with a stacked widget for the date, time and logo and then call (add) this to all other classes.
I'm not sure how to do this.

In QML, you would generally put the common code in a base class and subclass it to create children that might have values to certain fields that are different - but the same common fields. I use this technique to generate different modes in the same app that might need slightly different toolbars but the same canvas.
You might want to write the ui code in c++ for widgets, and then go from there.
Another approach might be to set the common values inside a model, and use those common values across the board.

Related

Qt Quick Dynamically Custom Layouts (like workspaces in an IDE)

The project I'm working on calls for workspace layouts for a large section of it, by which I mean that users can move around panes, resize them, close them, etc., like in VSCode (but more like Emacs since VSCode does not currently support both vertical and horizontal splitting).
The current methodology I'm considering to create a custom LayoutManager that has a json object and injects views into recursive Row and Column objects in a binary-tree-like structure. Before I start this undertaking, I'm wondering if there is a library or set of QtQuick (QML) elements that would let me do this a lot more easily or if there is a better approach to this problem. Or, please just tell me why I'm wrong in doing it this way.
Note: The technologies I'm using are C++ with Qt 5 (currently 5.10).
If you want highly customizable GUI, with the option of persisting UI configuration, it is best to design the whole thing model driven.
QML already has the necessary stuff - list views, repeaters and so on. QML is a little at odds with tree models, but you can essentially fake a tree by using lists of lists.
The model provided here will do the trick, with the added benefit it also supports declarative instantiation. So you can easily set up an initial GUI state declaratively, like you would with normal QML, but then allow the user to make modifications to that initial state which can then be saved and recalled.
Then all you have to do is bind the desired GUI elements to the underlying model data source objects.

Property Manager using Qt5

I am aware that Qt has a property browser extension called QPropertyBrowser. But I would like to make my own.
My question is, for the browser in QtCreator (see image below), how is it made?
Do they use a QTreeWidget with a seperate QTreeView and linked
model per category?
Do they use a single model and QTreeView and somehow create a delegate for alternating row colors for different categories? I assume it's this based off the single Property/Value header up the top (that controls the width of all columns together).
I know there is the 'All roads lead to Rome' response, but I'd like to know what the best way is, not just any way (this assumes the way they did it is the best way).

Can I "instantiate" (parametrize) prepared ui form by placing it in another form in Qt designer?

I created a simple form object representing some arbitrary name and value pair:
It's intentionally very simple - any design is to be applied through the CSS styles. Apart from the UI, the form consists of C++ class that handles the data loading and custom property defined in Designer too - the name of the data source (eg. hostname).
So I have two values I need to parametrize:
the Name - the QLabel text
the datapoint - some hostname. This will be later loaded by the C++ class and tell it what data should be loaded
I was Imagine I would be able to create "instances" of my form manually in designer and assign parameters to them. Like in this fictional image:
Don't forget datapoint is the custom dynamic attribute. I am sure the described design can be easily carried out programatically, but I feel like the designer solution will be prettier - provided there's a legit way to do it.
Maybe it's wrong, but the only way I can think of is making your Qt Designer aware of your widget. Something like this.
AFAIK, widget propagation doesn't allow you to edit custom properties without code, so you need a full widget support. My colleagues intentionally do whatever posiible from sources, not IDE& Forms, so that the project becomes more portable, but you are to choose yourself.

Use a single source file for many QtDesigner forms

I couldn't find my answer in the Qt documentation (maybe I'm inept), so here's a simple question:
Should I have separate source and header files for every QtDesigner form I have in my project, or can I (and should I) design all the GUI forms and then define their functionality in a single source and header file?
Consider this is a relatively simple project with ~5 forms based around a main window.
Qt Designer files has class generation definitions. UIC generates QWidget/QMainWindow based classes from them. You can use these classes from single class using aggregation method. But i don't recommend this if you don't know what to do.
My advice is to use it as Qt way. Use seperate classes and seperate files for each form. This approach is better. Every form should need its members and MainWindow can arrange communications (signal/slot connections and other logic) for these forms.

Customizing QDialog layout at runtime

I have Qt dialogs which need to adjust for a different locale at runtime.
The locale is set once at program startup and doesn't change.
I need to change both the label text and the ORDER of some text input boxes.
eg. Text boxes are day,month,year or month,day,year.
Is there a common/simple way to do this?
(note - it's not a simple date control, it's a complex industry specific thing. The date is just an example.)
If you are looking for a full automatic way to handle this, it would be too complicated because of a lot of scenarios and requirements.
A simple and intuitive way is to use QStackedWidget and put different layout on separate stacks, activate one stack according to locale at runtime. But how to handle the events or acquire data? embeded UI may help.

Resources