How to implement a tree view like the visual studio solution explorer with Qt? - qt

I want to implement a tree view like the visual studio solution explorer with Qt. The tree is used to represent an external data called "project". I want to use Qt model/view architecture.
(1) QTreeView for the view, and the model is derived from QAbstractItemModel which include a pointer pointing to the project object.
(2) The items under a directory are sorted by its name. When adding an item under a directory, it will automatically be put on the right position.
(3) When double clicking an item in the tree, a dialog will pop up for editing.
Any good ways to implement the (2) and (3). Thanks a lot!

Ad 2) Taking a look here might be helpful: http://doc.qt.digia.com/qt/qsortfilterproxymodel.html. It contains examples of implementing a more complex sorting and filtering of the items.
Ad 3) Overrride QTreeView::mouseDoubleClickEvent().
Just a side note, as an alternative, you could use QTreeWidget and QTreeWidgetItem, in which case you might want to traverse the tree and insert child items directly at the position you want.

Related

Implementing a QtDesigner-like behavior with QtDesigner

I want to implement an editing procedure like the one seen in QtDesigner. That is, having a toolbox of available "blocks" and being able to drag them into the working area of program to create a new instance of some sort of editable object (or widget).
I know that I can write it from scratch, but it seems logical that you can create something like QtDesigner within QtDesigner. I noticed that for toolbox they used a combination of Dock Widget and List Widget.
But I struggle to come up with the correct elements for the drag & create behavior.

QML Nested List View with separators

I'm trying to implement a tree view that represent structure of buildings/floors/rooms. All rooms should be classified by floor and building ( thus header for each building and floor is required.
First I implemented it with Repeater, Row and Grid elements. However i need a selection behaviour so i need to use ListView and GridView. However I have problems displaying nested list views.
Here's my code so far: http://pastie.org/private/3seqntgvskbyxnmnuluaua
Expected Result( when using Grid and Repeater instead of GridView and List View ):
Haven't tried it myself, but here is how to implementation a tree view in QML.
http://www.codeproject.com/Articles/632795/QML-TreeModel-and-TreeView
There is still no official tree view component in Qt (as of version 5.2). However, see the solution provided by jens on this thread
http://qt-project.org/forums/viewthread/30521
This is by far the best tree view that I have come across. It should provide a good basis for what you are trying to do.
Looks like Qt Company is releasing a QML TreeView in Qt5.5. Alpha release should be coming out in February.
http://blog.qt.io/blog/2015/02/05/licensing-of-new-modules-in-qt-5-5/

Qt Database content view / manipulation as list view

I have a database, which tables should viewed in a widget. Seems simple, but I can't decide what to du or use.
Each row of the table should be viewed as one list view item, for instance, imagine table with this fields: id, title, content, date, number.
I need to view it as a list view (not hard-coded, it may also be another thing, if it is possible or better), and the label of the list view item should be the title field. But when the user clicks or double clicks on that item it should open all the contents of the current row in a separate widget. The all of these can be implemented easily by me, but I can't understand what to use: QListView with its model, or QListWidget? Or maybe QSqlTableModel? The last one is unfamiliar to me, I can read about from documentation, but if you have heard or met some kind things/applications, please provide a better solution for described problem.
Hope I could explain my problem correctly,
Thanks in advance.
Have you read about model/view programming in Qt? Basically you should use some model (QSqlTableModel, QSqlQueryModel, QSqlRelationalTableModel or create your own) an then attach it to QListView or QListWidget.

How to display drop-down in column of QTableView and filter based on drop-down

I am newbie to Qt. I have to display a chunk of data in a QTableView and filter it column wise. For this I have used QSortFilterProxyModel, but as per requirement each column of the QTableView should have a drop-down list which shows unique values in that column. On selection of any of these values in the drop-down, only the rows having that particular value in the column should be displayed in the QTableView (Like you can do in Excel).
How would I implement this?
I had the same issue a week ago
I found a tutorial explaining how to do it. see link below
http://programmingexamples.net/wiki/Qt/Delegates/ComboBoxDelegate
Now my problem is how to retrieve the value of a specific combobox.
I think it is such a complex things to do in C++ and Qt display a combobox into a tableView.
For being a web developer at first I can tell that web language are better suited to do thoses kind of things.
But still some time performance matter and I tried to do it in C++ with Qt but it is not as easy as it seems to be in Web language.
This is very general question, and if I try to explain it all it will take pages, so it's better if you read the Qt model/view architecture documentation.
You can create your own class inherited from QTableView to create your customized table view. You have to use delegates for drop down functions and all. so read the QItemDelegate class documentation and documentation on subclassing delegates as well.
If you want to display it always and not just when editing, I would suggest setting a widget for the specific column like described in this thread: Qt - QTableView - Clickable button in table row

Best Qt Widget to use for properties window?

I want a widget like the properties window in Visual Studio or NetBeans. It basically has two columns: the name of the property on the left, and the value on the right. The value needs to be able to be restricted to certain types, like 'bool' or 'float' (with valid ranges), but should also support more complex types (perhaps requiring a popup dialog when clicked, and then it can just display a toString() version in the window. I'm sure I can add most of those features myself, but what's the best base widget to start with?
Oh... grouping of properties is good too (like a tree I guess). And property editing should invoke a callback (send a signal).
Qt designer has properties exactly like you want. They are most likely implemented with QTreeView. You can always look at the source code.
QTreeView or QTableView. Do all (ok, most) of the heavy lifting with a specialized model that handles all of your type restrictions and what-not. Check out delegates as well.
Here's a link led to github, it might be useful.
another userful link

Resources