Customizing MVC's view: is it possible to use CSS instead of delegate?
-
wrote on 25 Mar 2022, 17:21 last edited by deleted475
-
Hi,
Did you try to customize your list view ?
-
wrote on 25 Mar 2022, 21:09 last edited by
@SGaist Thanks! For some reason I didn't see QListView in the list of widgets customizable by CSS.
One question: is it possible to extract the size of a specific element? Because every time I add a string to the list, I need to enlarge the height of the view by the height of the element
-
Do you mean you want your view to be of the size of the number of element it contains ?
-
wrote on 28 Mar 2022, 13:50 last edited by deleted475
@SGaist Yes. I'm trying to create a Telegram-like dropdown, if you know what I mean.
This dropdown can be enlarged in height up to some maximum value, - then a scrollbar appears. Therefore, to begin with, I need to know the height of an element, so I can manually enlarge the dropdown. For example:
// Not a real code! int newHeight = view->height() + view->elementSize().height(); view->resize(view->width(), newHeight);
-
Would it be simpler to use a QComboBox ?
-
wrote on 28 Mar 2022, 18:51 last edited by deleted475
@SGaist For the current stage - yes. But in the future this popup will be extended so that each item will have an avatar, last login time, etc. along with the text.
-
In that case you will need a QStyledItemDelegate.
-
wrote on 28 Mar 2022, 19:14 last edited by
@SGaist Thanks! Last question - as far as I know, delegate is used to draw each item individually. But, returning to the dropdown example, it would be logical to set its model in form of
Avatar File Name | Username | Last Login
Is it possible to still use list-like view and draw a visual element composed of these three features? -
Each item does not mean you cannot use data from different parts of the model.
The model that feeds your list view will likely be a table, so in your delegate you will retrieve the data from the siblings of the current index to do your painting.
1/10