QT QtreeView show image when tree is expanded and collapsed - qt

I have a requirement in the TreeView where I have to show down arrow image when tree is collapsed and up arrow image when tree is expanded and this is applicable for each parent item in the tree.
My UI will have only 1 column and this arrow images i have to show at the end of the row.
I am using QTreeView and I can see expand and collapse signals.But it does have only index arguement.But I need item rectanlge details to show the image at the end of the row.Could you pls suggest is there any way to achieve this?
Thanks,

The simplest way would be to use QTreeView::setIndexWidget (inherited from QAbstractItemView). With this method, you can set your own widget to render the nodes.
If you have more sophisticated requirements, you need to implement a custom delegate. Please have a look at the QAbstractItemDelegate Class Reference and Designing Delegates. By the use of delegates, you have complete rendering control over your items.

Related

Complex content in QTableView

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.

QTreeView parent item style

How could I make the top-level items of a QTreeView look like "Layouts" or "Spacers" in the capture image.
is there any way to add separator to the QListView?
thanks
You can use custom delegate to achieve this. Therefore, you need to re implement paint method.

How to implement a Clickable Widget for QListView?

I want to implement my own Widgets for a QListView. Like this:
If i click on this widget i want to do something.
In time, I only have experience with the QML-Version of the ListView.
Can someone explain how to insert this widget to the a QListView?
Greetings
UPDATE
In my Project i want a GUI like this:
In my first ListView I want to show items, that has a ListView, too. The text of each item can to be update.
There are 2 ways:
Set custom widget for each index: QAbstractItemView::setIndexWidget. Note: there may be problems with interaction with widgets. This way is typically used only for displaying static content.
Create custom QStyledItemDelegate and override editorEvent method. See model-view programming for details.
Update:
I propose you next design:
Create widget with image list + "dynamic content" + labels
Create ScrollArea with vertical layout and add there widgets (1.)
(2.) is prefferable than simple listview, because listview doesn't design for such cases. Listview designed for showing some data, but not to be a container for other complex widgets.
Pros: you will have fully interactable widgets.
Cons: you need to code a bit ;)

How to use Qt's Model-View programming

I'm trying to display some cards into a QListView but I'm really having trouble understanding how to use Qt's model/view pattern, and I can't find any simple examples.
Basically, I have two classes:
Card - my "model" which contains the name of the card, id, etc.
CardWidget - can load and render a Card object (display the card name and other info)
So how can I use Card and CardWidget to display a list of cards into a ListView? Do I need to change something to my classes, or should QListView be able to display them directly?
If someone could show me the basic steps or point me in the right direction that would be perfect.
See the documentation of QAbstractItemDelegate, which has an example of rendering items in a QTableView.
Its not obvious what you are trying to do here - in a list view, you can render a view of an item which is not the same as having a widget in every cell.
An item delegate can provide a widget as an editor and also how to render a cell's contents.
If you actually want fixed widgets in the view, you could use QListView::openPersistentEditor on all the cells you want a fixed widget for. The item delegate should outline how to create an editor for the cell in question.

Custom draw a List component in Flex with AS3

I need a List component that will display custom data. I want to extend a spark List or any List component and add my code to paint each item.
I done this in other frameworks but for Flex i found only simple examples that change the font and background color, i need access to a Graphics object to paint my items as i need,is there a method that i can override or some example /class i should look at?
All UIComponents has a 'graphics' property that you can draw to, however, I'm not too sure why you'd want to extend the list component just to paint each item. Each item renderer is responsible for painting itself. If anything, just use the normal List and specify the itemRenderer property to point to a custom item renderer of your own (that extends ItemRenderer) that can take in data and paint things accordingly.

Resources