Customizing MVC's view: is it possible to use CSS instead of delegate?
-
I have a custom widget that serves as a container for labels. Both it's style and labels' style I set with CSS.
But now that I'm switching to MVC model, it looks like this:
Is it possible to reuse the already existing CSS configuration file and not set custom styled delegate?
-
@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 ?
-
@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 ?
-
In that case you will need a QStyledItemDelegate.
-
@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.