QTreeView parent item style - qt

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.

Related

Editable QTabWidget

I want that user could rename tabs: clicking on current tab label should turn on editable mode.
The only way I can see is to use stacked layout + scrollarea + custom widgets + stackedwidget.
Can I do it with standard QTabWidget?
And one more question. Can I create custom pseudo states (like predefined :hover, :selected etc)?
You can reimplement QTabWidget to get access to QTabBar and use QTabBar::setTabButton method. But sometimes it is difficult to adjust position of inserted widgets ;)
You can't create custom states, but you can use custom properties. See Q_PROPERTY macro and related QSS syntax. Note, that styles will not updated on property change, so you should manually call polish/unpolish to force widget to use QSS.

QT QtreeView show image when tree is expanded and collapsed

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.

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.

How to set accessible name of QActions contained in a QMenu

I'm trying to set the accessible properties of a QMenu's sub items. I can set the accessible property of the parent menu using setAccessibleName() since it inherits QWidget. Unfortunately, the QActions that you add to the menu aren't widgets child classes, they inherit QObject directly.
Is there a way to set the menu items accessible name?
Thanks
I've never used this aspect of Qt but it looks like you have to use the QAccessibleInterface framework.
There is a subclass of this for QObject, namely
QAccessibleObject. This still has some pure methods from the base so you'll need to provide some methods.
From what I can gather from a quick look at the documentation you can either provide a QAccessibleObject wrapper for the whole menu or for each action individually. If doing the latter then you would implement childCount() to return 0 and role(int i) to return QAccessible::MenuItem.
I'm not sure if this would work in your case with menu, but I solved mine where o->parent() returns QObject like this.
dynamic_cast<QWidget*>(o->parent())->setAccessibleName("whatever");

Can I use a different ItemRenderer for different list items?

I have a Flex list and a custom ItemRenderer. I'd like to be able to have some items in the list use a different ItemRenderer (say, depending on the class of the item). Is this possible?
E.g.:
<s:List dataProvider="{_systems}" itemRenderer="myItemRenderer"/>
Most items in _systems use myItemRenderer. But if element 3 of _systems is "specialSystem" the renderer would be "specialItemRenderer".
Is this possible?
Use an itemRendererFunction.
Here is a blog post tutorial on that. I also touch on this here.
You use Canvas as ItemRenderer and implement mechanism which will create other controls automatically.
More details you can find in this article: Different Items renderers in List
The main idea:
You create special ItemRenderer which
can create "emulate" other controls,
in our case it is subclass of Canvas
which simply creates and adds desired
control. Then we need some mechanism
to tell our container which renderer
we want to emulate, for this purpose we
use ItemContainerData with special
fields.

Resources