I have a model based on QAbstractTableModel that I would like to use to display its content in a list in QML.
Actually, I need to display the first column only.
TableView does not exist in Qt Quick Controls 2 and suffers from performance issue and rendering issues on HiDPI devices.
There is suggestion in this question to use a ListView. But I fail to see how I can tell the model that I need to display the first column only.
Is there any solution for this ?
This is automatically done in QML by ListView: the first column from the model is taken for any requested role.
Related
We would like to do a TableView that allows complex content in its cells.
The TableView should be as generic that I can do simple stuff like in picture 1. The left image is a simple example, where I fill a simple TableModel, set it for the TableView and display it.
But what if I want to add more complex content to one cell? Please again look at the first picture. The right part is more complex, for every cell we want to display an image, a description, and more description, so three items in one cell.
I understand, that I can put widgets to the cells of a TableView.
But, if I want to have a proper TableModel in the background, how would I store the data?
On top, the view should automatically resize when I make the widget of the TableView smaller the content should adapt
So if I use TableView and want to resize, I would have to shovel the content from one colum to another.
From what I understand, the columns also define the layout.
Would I be better of if I used a QGridLayout for this purpose?
Do I have to define a completely new model for QGridLayout?
Thanks for any help!
I am a newbie to QT and would appreciate your input a lot!
Qt's proposed solution to having a complex view in each cell of a table view is to use a custom delegate. Take a look at Star Delegate example, it demonstrates exactly this technique.
There are basically two options to proceed with a custom delegate: either you subclass QStyledItemDelegate (or its base class QItemDelegate if you need to draw the items of Qt's datatypes somewhat specially) or subclass QAbstractItemDelegate to have the full control over the delegate's appearance and behaviour.
However, your second requirement of automatic layout rearrangement on widget resizing suggests that your view doesn't really has to follow the underlying table's schema. Qt has a flow layout example which implements a layout with exactly this rearrange-on-resize property and I suppose the simplest approach would be just using this layout along with custom widgets representing the table model's cells. To make it happen you could implement a custom view class listening to the model's signals and creating/deleting widgets and updating the flow layout as necessary. This book, even though a little outdated nowadays as it covers Qt4, contains a chapter (#6) on implementing a custom view which is not a subclass of QAbstractItemView but is just a widget updating itself as its underlying model updates. To me it feels the right approach to your problem.
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/
Does anybody knows how to create a table view using QML(Qt Quick 1.0)?
Tell me all ideas you have, my ended, I'm writing on PySide so unfortunately I can't use QtQuick 2
Depending on your requirement, you can use one or combination of :
Qml Grid view
Combination of Qml Row and Column
List View
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
HI..
i am new to QT,i want to know how to customize the listview in QT i.e i want to add multiple icon in single row.. etc.. i tried lot i am not getting how to do that..
i tried with Qlistwidget, in tat i can only insert single row with one image.. i am not able to place multiple icon with desired locations..
please assist me, which control is good listview or listwidget.
and how to customize the same according to my view
if you have any sample examples. please provide me the link.
Thanks
You can implement a delegate to customize the rendering of the items in your view.
From the model/view programming docs: delegates are responsible for rendering individual items in the views.
See the pixelator sample for example usage.
Take a look at QTableView or QTableWidget. You can insert the icons in the first two columns and the text in the third column. Or any other way you like it.
I guess you can use some delegates.
Have a look at http://qt.nokia.com/doc/4.6/model-view-delegate.html
Hope it helps !