Populating a QTreeView on an existing application with a QFilesystemModel - c++

I have an existing Qt application with buttons and other widgets on it. I would like to add a QTreeView (or QTreeWidget) to the application, and populate it with a QFilesystemModel.
I have seen examples and read the Qt documentation on using QTreeView and QTreeWidgets but they are always just creating a standalone QTreeView on its own, which I can replicate fine.
I used QtDesigner to add a QTreeView on my application, but i cannot work out how to use the QFilesystemModel to populate it.
How do I access the QTreeView on my application and set its model to the QFilesystemModel?

Related

How to manage multiple SQLite databases in a Qt C++ program?

I am writing a program in Qt creator. I have a treeview and a tableview. Each time an item in the treeview is clicked, I need to update the tableview. The problem is that the tables realted to each tree item is different. Since the tableview works with SQLite databases, I have decided to create a database and a qsqltablemodel for each of the tree items and set the qsqltablemodel for the tableview upon each click on the tree item. I guess the tableview should update then. To implement this, I need at least 60 databases and models and am thinking if there is any issue with having mutiple databases and how to manage them effectively.

Changing QTreeview checkbox to icon without using stylesheets

I wanted to have a QTreeView with icons ( which act as a checkbox ) followed by some text from a subclass of QAbstractItemModel. I cannot modify or change the structure of this QAbstractItemModel.
When I use this QAbstractItemModel with QTreeview, it shows checkbox followed by some text and performs the intended function required. I just wanted to change this check box to on and off icons.
I found this:- Customizing the checkboxes of the items of a QTreeView
But, I cannot use stylesheets in my case as the icon I want to use some system icons which are loaded using icon loader which returns a KIcon instance ( subclass of QIcon ).
What would be the right way of doing this?
I saw this tutorial and tried creating an editor for a checkbox. But, how should I register editor as QVariant does not have Qt::CheckStateRole type?
I tried using Qt::Int, but it doesn't works

Add Items to QListWidget add design time

Is it possible to add items to a ListWidget during design time. I am using QT Designer however I cannot find any options to add items to a list widget at design time. Any suggestions ?
You need to simply insert a QListWidget in a form when design your GUI in Qt designer. Double clicking on the QListWidget will open another Edit List Widget dialog that will allow you to customize it: insert new items, change properties etc.

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

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.