Is it possible to set a property on QTreeView item - qt

QSS allows styling QTreeView and has a set of predefined child elements, e.g. QTreeView::item.
I would like to add finer model-driven granularity to it using property selector (QTreeView::item[myproperty=myvalue]). This way I could have data-driven display and at the same time it would be customizible via QSS.
Is there a way I could access the item of QTreeView (note, not the QTreeWidget), so that I could set a property on it based on the data returned from the model?
Are there any other ways of driving which style to apply to a given item from the model (other than returning font, color etc)?

Related

How to access child views of CollectionView?

There's a few cases where I would like to access the child views of CollectionView. Here's a few examples of why:
CollectionView doesn't set the Selected VisualState on the selected item, when the item is not a reference type (for example an enum), and the SelectedItem is set in code, either by setting the property, or by data binding. So in order to support the use enums in my CollectionView, I want manually set the VisualState when the selection changes.
CollectionView always has the height of 100% of screen height. It's not very practical in many situations, and in some cases where I know it's only a few items, I want to calculate the height of all children, and set the HeightRequest of my CollectionView accordingly.
As a workaround, I've used StackLayout with BindableLayout.ItemsSource instead of CollectionView. Here, I had access to the child views, and am able to set the VisualState of children as I please.

How to change the style of Mpart tab in RCP application by css?

I have an application where I want to set the color of a tab dependent on the displayed data, using an id or a tag.
I could only find examples on how to set the color of selected and unselected tabs. Is there another built in possibility for styling tabs, or will I need an own renderer?
Note:My partstack has so many mpart and for each mpart tab i want to set color depending on data.
There isn't any way to do this with the standard CSS support.
You will have to use the e4 CSS swt-tab-renderer property to define a new tab renderer, probably based on the e4 org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering renderer. Even then I think this will be difficult.
You also use the org.eclipse.e4.ui.css.core.propertyHandler extension point to define new CSS properties.
The org.eclipse.e4.ui.css.core.elementProvider extension point allows you to define new CSS pseudo classes (such as :active) but this might be difficult to use in this case because an element provider is already defined.

Angular2 Nested Visibility

I am implementing a recursive component that displays tabs and uses visibility to show only the active content. I choose this approach because the tab contents are expensive to generate and to layout from a DOM perspective.
based on this, i see that when i hide a tab, the nested child tabs are still visible.
I am thinking that the best way to handle this is by creating a set of css classes:
p-visible
p-visible-hidden
This way, I can recurse through the DOM elements when a tab is set to hidden and change any elements having a p-visible class to having the p-visible-hidden class instead. Similarly, when a tab is set to visible, i can switch all of the elements that have the p-visible-hidden class to p-visible.
So I'm wondering the best way to implement this in Angular2 - To me, the best way maybe to actually select the child DOM elements.
Thanks in advance for any help :)
test harness for component
tab layout component
I was able to solve the problem by creating an #Input boolean (called parentVisible) that indicates if the parent is visible or hidden. This property is cascaded down through the recursive hierarchy of components.
The parentVisible boolean is an additional filter on setting each child element's visibility (if parentVisible is false, the visibility is set to hidden, if parentVisible is true, then set the visiblity as before)
This strategy makes it possible to avoid direct DOM manipulation which is deemed good for unit testing and doing things in the Angular2 way :smile:

Displaying a QStandardItem with its foreground color in a QTreeView even when it is selected

Using Qt 4.6.3 on Linux/X11.
I have a QTreeView widget which uses a QStandardItemModel as its model, with 4 columns and hundreds of rows. Most of the items in the list are to be displayed with a standard color, but a few need to be of a different color. I can change the colors of those few items easily with QStandardItem::setForeground().
However, that only affects the color of the item when it is not selected. When I select a colored item, its background color changes to blue (which is ok), and the text color changes to white (which is not ok). I tried using a stylesheet to affect the foreground color of selected items (with selector QTreeView::item:selected), but it affects all items.
I would like items for which I called item->setForeground(Qt::red) to remain red even when they are selected, and other items to use the default set of colors (which they already do). How can that be done?
The colors being used are (I assume) those for the QPalette's Hightlight and HighlightedText roles. Unfortunately, I don't know of any way to set those on an individual standard item.
However, since standard items are used in the model/view framework, you have another option. You should be able to create a delegate to paint the view however you want to. I would recommend inheriting from the styled delegate, and calling the parent class's functionality as much as possible. Likely, you'll only need to change a few parameters in the cases where an item is selected and has a non-standard foreground color.

Formatting AdvancedDataGrid Cells

I have a quick question about rendering the advanceddatagrid cells.
I need to programatically color the cell of the datagrid based on the conditions. Lets say, the stock quotes. If there is an increase from the previous day, I need to have the cell colored in GREEN and in RED, when there is a decrease.
Now, the important part here is, I need to do these things dynamically, which means, when the user enables the comparison/conditions, then the cells are colored. And when the user disables the comparison, then it again goes back to its default behavior.
I know I have to use renderers. But not sure, how to use it for the cells and that too dynamically. Can anyone please explain how to go for it?
Thanks
Item renderers are components used to define the appearance of a component's "items" or subcomponents. In the case of the ADG, the "items" are the individual cells. You can create a completely custom class to function as the renderer (given it implements certain required interfaces) or, in most cases, you extend an existing component. Since the default renderer for ADG cells doesn't support background colors, you have to create or extend a component that does and use that as the renderer. That is the basic premise that these tutorials, linked to in the following question, work from:
Setting background color for datagrid row in Adobe Flex
After creating an itemRenderer that supports a background color, you have two options as to where you can define your "conditions"; inside of the itemRenderer or using the ADG's styleFunction (additionally requiring that your itemRenderer defines a "background" style).
In your case, you could include both today's and yesterday's stock price values in the data sent to each cell and compare the two to determine the color used to draw the background. Again, more on that in the tutorial links provided above. In either the itemRenderer or the styleFunction, you would compare properties on the itemRenderer's/styleFunction's data object (corresponding to the row you're looking at), e.g.:
if(data.today > data.yesterday)
{
// set color or return style
}
else ...
To "toggle" custom cell colors, switch between your custom renderer and the default (colorless) renderer. In other words, set the itemRenderer property to your custom itemRenderer class when you need display the colors and set it to "null" when you want the "default behavior".

Resources