How to include QList in QTabWidget with QWidget - qt

First of all, I code with the help of the Qt Creator.
For a private project I want to build a Tab box with 3 pages, while each page should represent a table/listing of different attributes of objects.
The objects are in a QList (Container), 1 for each page.
I just want to show/display, not to change the information.
I already created a QTabWidget object and a QWidget object for each page.
How can I represent the information? is there a specific class of QT I could use?
How do I access the single attributes of an object?
Thanks in advance

The QList is a class for creating and managing list-based data. To render that in a model (your QTabWidget) you need to map the model using QListView.
QListView details

Related

Qt custom widgets with custom items - Qt Designer/ uic

I have started working with Qt again. What we want to do is to automatically generate graphical user interfaces. Therefore I have taken a closer look at the .ui file format (which is a XML based file format). These files are generated by the Qt Designer but can be easily be created by any other software. This part works so far.
But: we want to add some custom widgets. Creating custom widgets is also not that difficult. Some good websites exist out there: Creating Custom Widgets for Qt Designer, Using Custom Widgets with Qt Designer, (more hyperlinks held back),...
My question is rather: how can you implement custom widgets displaying custom items. Let's take one example. We have a QComboBox and a QSpinBox. The combobox has three items
A
B
C.
When selecting "A" I want the spinbox' minimum set to 1, maxiumum set to 9; when selecting "B" the spinbox' minimum should be set to 10, and its' maximum to 99; selecting "C" should set the spinbox' minimum to 100 and the maximum to 999. How is this done properly?
At the moment I set the data in a QTableWidget which is a helper class for me. Each row has three columns/cells:
item | min | max
-----+------+-----
A | 0 | 9
B | 10 | 99
C | 100 | 999
And I have my custom widget which contains the QComboBox and the QSpinBox. At runtime I tell the custom widget to take data/model from the QTableWidget and copy to itself by a method called setFriendContainer() [it's even a public slot which should be connected to a signal from the tablewidget which is emitted automatically]. Afterwards the tablewidget is not needed any more! I don't even want to show it to the user at all (this is why some size properties are set to 0; but it's partly still visible).
I think this is not really a clean way to implement it. What would be better/ an alternative? The items are also generated and should be contained in the same .ui file. Of course it would be possible to load it at runtime from another file, but I think this isn't rather an option. Do you think my workaround is ok, or is it too "ugly"? There are some examples where you can see how to add single custom properties, but I think this is something different - if you want to add whole containers (lists or tables of items, whatever). But including it in the .ui files might even be against the whole model/view concept?!
Any help welcome!
Thanks,
Matthias
I have added our data in a custom property in the form of XML. The data stores some coding information used in the widget. It's good to have the dynamic properties.
Remember that you are dealing with the properties of the widget. A UI file is nothing more than a description of the widgets, their properties, and their relation to each other in the hierarchy. A custom widget is no different than something like a QPushButton or QComboBox to Designer. The important thing is to encode the properties of your custom widget in a way that is understandable in the UI file.
You probably are best served by looking at the UI schema and making sure your widget can be described in a valid file. After that it's just to make sure that your properties behave correctly (i.e., that you can set properties in any order and get the same result). How you implement the widget is really up to you (make your own data structure, don't drag an "invisible" tree widget in).

Qt Designer dock widgets children acess

I made a form using the Qt Designer which has some dockwidgets, these dockwidgets have some children widgets. How I can access the dockwidget and these child widgets in my mainwindow.cpp?
I highly recommend reading the docs for these kinds of things, but to give you a little head start, QDockWidget inherits from QWidget, which inherits from QObject:
https://doc.qt.io/qt-4.8/qobject.html#children
widget->children() would simply tell you the children of this widget. This would be needed if you didn't already know the names of the objects to be accessed directly, or had no reference to them.
Update
When you create objects in Qt Designer, and you run the setupUi(this) that is generated for you, inside of your MainWindow, you will then have access to all of the widgets you had set up as members. You can access them directly as they were named in Qt Designer. Please check out one of the numerous tutorials on getting started with Qt. Here is one that shows you how to make use of your ui file, and access the members from it: http://sector.ynet.sk/qt4-tutorial/my-first-qt-gui-application.html
You can also get a list of all the dockWidgets from the mainwindow with
QList<QDockWidget *> dockWidgets = findChildren<QDockWidget *>();
A similar technique works for getting toolbars etc. so you don't have to manually store a list as you create them

What is the name of the Qt widget used for filling text in gnome planner?

The screen shot has been attached.
There is a kind of tree shaped widget in which you can fill in details, I wish to know its name.
Do QTreeWidget or QTreeView do the trick?
Do we have such a widget in Qt (in which text can be entered at run time)?
The QTreWidget is used when you want to display a simple tree with standard items.
The QTreeWidget class is a convenience class that provides a standard
tree widget with a classic item-based interface similar to that used
by the QListView class in Qt 3. This class is based on Qt's Model/View
architecture and uses a default model to hold items, each of which is
a QTreeWidgetItem.
The QTreeView is used when you have more complex models and gives you more flexibility
A QTreeView implements a tree representation of items from a model.
This class is used to provide standard hierarchical lists that were
previously provided by the QListView class, but using the more
flexible approach provided by Qt's model/view architecture.
I believe (I have not checked the corresponding code) that in the Gnome planner what you see is can be implemented QTreeView with custom QAbstractItemDelegate. Notice though but most Gnome applications use GTK and not Qt.
The QAbstractItemDelegate class is used to display and edit data items
from a model.
A QAbstractItemDelegate provides the interface and common
functionality for delegates in the model/view architecture. Delegates
display individual items in views, and handle the editing of model
data.
You should study the Qt Model/View Programming. It may has a steep learning curve but once you get familiar with it you can implement almost everything.
On some other forum I have been told that there are editable trees in Qt:
http://doc.qt.io/qt-5/qtwidgets-itemviews-editabletreemodel-example.html
Here we can add/remove columns and text.

Qt: How to connect class to custom Qt Designer Widget

Maybe I'm thinking about this completely wrong...
I've created a new widget in Qt Creator with a Designer file (I picked the Widget template, which generated a source and header file for my custom widget class, and also a designer file).
I then designed the widget with the Designer. I can now create instances of this widget and it will show up in my app.
But it's not terribly useful because I don't know how to customize the widget at runtime.
Let's say all I've got in the widget is a Label and a Button. At runtime, how can I change the text of this label? I can't figure out how to connect the designer stuff to my actual class, and I can't find any documentation on how to do this. Am I missing something?
Thanks!
A few things:
In designer, each of your widgets (the QPushButton, and the QLabel in your case) has a name assigned to it. This name is the name of the variable that you can use in C++ to reference that widget and call functions on it.
Depending on how your custom widget was implemented, you will be able to reference these variables using one of two methods:
If your class inherits from Ui::MyCustomwidget, then your variables are simply member variables of your class and can be accessed at any time (myLabel->setText())
If you have a member variable (generally named ui, of type Ui::MyCustomWidget), then you can access your widgets using the ui object (ui->myLabel->setText())

How to retrieve text from within QGraphicsView?

I'm attempting to retrieve certain text from a QT based window (on Windows). The text is contained in a QGraphicsView (actually, a class that inherits QGraphicsView).
I'm able to intercept it with a series of hooks due a specific call hierarchy in the application, though this is not a very desirable solution.
While the particular text item is likely to be custom, it would be of great help to just enumerate all the items in a QGraphicsView - if possible with class names.
Any pointers on how to go about this will be appreciated.
Note:
I've been having problems with the items() function of QGraphicsView, it seems to be impossible to iterate over either with QListIterator or with items().at().

Resources