selection color of the items delegated in a tree widget
If "row" item is selectable on the tree widget, when the row is selected, the row is highlighted, that is, it is colored with a color (blue as default). If the tree widget has some delegated items (like comboboxes, spinboxes), the delegated items do not seem as if they were selected - they are not highlighted -.
How can we handle this? I mean, when I select the row, I want all the items to have been selected, and also, when I select a delegated item, I want the row item to have been selected. Is the only way to implement it via signal & slot mechanism? I mean, if one delegate item is clicked, the row and all the delegated items included should go into 'selected' status and vice versa (if the tree widget is selected, all the delegate items are selected.).
Thanks for your guidance...
Re: selection color of the items delegated in a tree widget
Did you use the style aware QStyledItemDelegate to implement your delegates?
Re: selection color of the items delegated in a tree widget
I have not used it! I will try it now :)
Thanks for your help!
Re: selection color of the items delegated in a tree widget
Hello franz,
I could not understand the relation completely after my search. Could you please give more hints?
Thanks...
Re: selection color of the items delegated in a tree widget
It could be that QStyledItemDelegate doesn't directly help here. The table cells in your view are managed by the view, so the view can set the background color based on what the delegate hints at (or not). There is probably nothing that tells your widgets to change their color.
Re: selection color of the items delegated in a tree widget
I realize this thread is quite old - but I currently have QComboBoxes emplaced within cells in a QtableView, and wondered about the possibility of the Combo(s) coloration being linked to the associated TableView cells.
The coloration of cells in the TableView occurs only at initialization, but what I am finding is that with the subclassed QStyledItemDelegate Combo(s), none of the background coloration is applied.
Re: selection color of the items delegated in a tree widget
Well, although in different context, I'm still compelled to share the solution I found (for PyQt 4.7):
Required row based indexing coloration in QtableView with intermittent cells containing QStyleItemDelgate(s) QComboBox(es)-
Code:
class comboDelegate(QtGui.QStyledItemDelegate):
def __init__(self, parent, maxNumber):
QtGui.QStyledItemDelegate.__init__(self, parent)
self.maxNumber = int(maxNumber)
def createEditor(self, parent, option, index):
self.comboChoices = ['pen','keyboard','sword']
if index.row()>self.maxNumber: background = 'rgba(211,211,211,255)'
else: background = 'white'
combo.setStyleSheet('QComboBox{color:black;background-color:'+background+';\
border-color:black;border-width: 0px;border-style:solid;}\
QComboBox QAbstractItemView{outline:0px;}\
QComboBox::drop-down{subcontrol-origin:padding;\
subcontrol-position:center right;width:10px;right:2px;\
border-top-right-radius:0px;border-bottom-right-radius:0px;\
background:none;}')
combo.addItems(self.comboChoices)
combo.currentIndexChanged[int].connect(self.currentIndexChanged)
return combo
#... Some other Delegate related functions ...