How to `QTreeWidgetItem::setBackground()` to all of the items associated with it.
-
Hi,
1)I haveQTreeWidget
and there are manyQTreeWidgetItem
attached to it.
2) for each of theQTreeWidgetItem
I want to set the background color, to do this I have doneQTreeWidgetItem::setBackground(0,QColor(Qt::green));
, but problem is, it is changing the color only if the item gets selected. I want to set it to all. how to do it? : here the link to output the image .
3) My final aim is to achieve this User interface: link to imaget please help me to achieve it. -
What items should be set to green? You can access the children via http://doc.qt.io/qt-5/qtreewidgetitem.html#child and all top level widgets with http://doc.qt.io/qt-5/qtreewidget.html#topLevelItem
-
What items should be set to green? You can access the children via http://doc.qt.io/qt-5/qtreewidgetitem.html#child and all top level widgets with http://doc.qt.io/qt-5/qtreewidget.html#topLevelItem
What items should be set to green?
I want to set to all the sub-items of the alltoplevelItems without the selection item.
-
So my proposed functions are exactly the ones you need for this.
-
Hi
just to make sure that you noticed
setAlternatingRowColors(true);
http://doc.qt.io//qt-5/qabstractitemview.html#alternatingRowColors-propthat color every other row.
and you can control the colors withsetStyleSheet("alternate-background-color: yellow;background-color: red;");
Im not sure if you just want alternating colors or something more fancy :)
-
Hi
just to make sure that you noticed
setAlternatingRowColors(true);
http://doc.qt.io//qt-5/qabstractitemview.html#alternatingRowColors-propthat color every other row.
and you can control the colors withsetStyleSheet("alternate-background-color: yellow;background-color: red;");
Im not sure if you just want alternating colors or something more fancy :)
-
Hi
just to make sure that you noticed
setAlternatingRowColors(true);
http://doc.qt.io//qt-5/qabstractitemview.html#alternatingRowColors-propthat color every other row.
and you can control the colors withsetStyleSheet("alternate-background-color: yellow;background-color: red;");
Im not sure if you just want alternating colors or something more fancy :)
-
@thippu
hi
I dont think u can specify on which ones. its all or nothing.
In such case, the functions mr @Christian-Ehrlicher mentions can be used to handle your own coloring.
You can try set topcolor to new color after you have inserted it.
Im not sure if its possible to override with setBackground or if the alternate code will change it back.
You should test it. -
@thippu
hi
I dont think u can specify on which ones. its all or nothing.
In such case, the functions mr @Christian-Ehrlicher mentions can be used to handle your own coloring.
You can try set topcolor to new color after you have inserted it.
Im not sure if its possible to override with setBackground or if the alternate code will change it back.
You should test it. -
What items should be set to green?
I want to set to all the sub-items of the alltoplevelItems without the selection item.
I want to set to all the sub-items of the alltoplevelItems without the selection item.
I'll just throw in that assuming you can address the items with a selector (e.g.
QTreeWidget > QTreeWidgetItem
== top-level only,:selected
== selected only), astylesheet
rule (or two) could allow you to do this in one go without iterating anything.... -
I want to set to all the sub-items of the alltoplevelItems without the selection item.
I'll just throw in that assuming you can address the items with a selector (e.g.
QTreeWidget > QTreeWidgetItem
== top-level only,:selected
== selected only), astylesheet
rule (or two) could allow you to do this in one go without iterating anything....