Adding an inheritance to an Qt designed object - c++

I have a problem and I want to implement the MVC pattern to my QT application, that's why I need for example to inherite in my QTableWidget about another class like
myClass
{
myMethod();
}
but our QTableWidget is contained by our Mainwidows that is designed by the QT designer and generate an ui_MainWindow class !
Do you know how to do that ?
Is that a method inside the Qt Designer to do that ? or another method ?
Thank you for your answer !

You can use custom objects in QDesigner. Right click on the widget that you want to have as an instance of a something that is not available in designer and select "Promote to ...". In that dialog you can enter a custom class and a include file where the declaration for your class can be found.
BUT Qt implements uses MVC for a lot of the classes look at QTableView as opposed to QTableWidget, QTableView uses QAbstractItemModel as the model class and there is a pretty strict separation between the view and the model. See also An Introduction to Model/View Programming # Nokia

Related

Qt: model/view concept with text browser

I am writing an application in Qt with C++. In this application I have to display an amount of data in a text box.
Is there a way to use QTextEdit or QPlainTextEdit with the model/view concept in Qt? I only found list, tree, or table View classes with mvc functionality.
Is there a way to use QTextEdit or QPlainTextEdit with the model/view concept in Qt?
No.
For using model/view concept you need use already existed classes which inherit QAbstractItemView (such as: QColumnView, QHeaderView, QListView, QTableView and QTreeView) or inherit your custom class.
Have a look at the Qt documentation. There are the options you have:
http://doc.qt.io/qt-4.8/model-view-programming.html
Models
QAbstractItemModel provides an interface to data that is flexible
enough to handle views that represent data in the form of tables,
lists, and trees. However, when implementing new models for list and
table-like data structures, the QAbstractListModel and
QAbstractTableModel classes are better starting points because they
provide appropriate default implementations of common functions.
Views
QListView displays a list of items, QTableView displays data from
a model in a table, and QTreeView shows model items of data in a
hierarchical list. Each of these classes is based on the
QAbstractItemView abstract base class.
Controller
QAbstractItemDelegate is the abstract base class for delegates in
the model/view framework.

Common ui base for dialogs in Qt

In Qt widget application, I'd like to have a common base view for all my dialogs, so that I could inherit other classes from it.
This "base/common" view would contain initially a set of buttons at the bottom and a custom frame with data at the top. A place in the middle would be used by derived classes for placing view-specific contents. If the common dialog style changes in the future, changes will be applied in one class only.
Is there any way to use such approach in Qt, since ui files are processed with 'uic' to create classes? Ideally would be to not to lose the ability of using the gui designer, at least for the derived classes.
Any hints much appreciated.
You can make your "base view" as its own ui file with a big QFrame in the middle with nothing in it and name it contentsFrame. Then create your other widgets you want to place inside the empty contentsFrame in designer.
Now you have a couple options. You can have both open side by side in designer, click on your contents widget, select all, and drag everything to your contentsFrame. Then just hit save as and save it as a different widget. If you aren't afraid to leave designer for a tiny bit, you can add your contents widget to the base widget in code. Either way, make sure you are setting the layout for your contentsFrame or everything will look like garbage.

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.

How to create a Multi widgets Qt application

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

Qt - ComboBox automatically in TableView?

So in my project, I had a TableView and i edited some of its info's in the Qt Editor itself. I also implemented all the codes for it and when I ran before, I could see a comboBox in a place of int. But for some reasons I had to replace that TableView with a new one. All the codes are the same, but I don't see any comboBox now. So does that mean the comboBox appeared for something done in the Editor?
If you replaced your TableView in the qt designer and gave it the same name as before it shouldn't do anything to your c++ implementation of your class. The settings you enter in the qt designer will be deleted when you delete the TableView and you have to re-enter the ones you had before. So you can still use your previous c++ implementation of your class.
I usually design my gui in qt designer and then create a class that sets up signals/slots and initializes the widgets to my liking. So if you had setup your widgets from your class constructor you wouldn't have to worry about any of this.
Good luck!