PDA

View Full Version : selection color of the items delegated in a tree widget



fulbay
3rd December 2010, 10:20
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...

franz
3rd December 2010, 21:36
Did you use the style aware QStyledItemDelegate to implement your delegates?

fulbay
7th December 2010, 07:41
I have not used it! I will try it now :)

Thanks for your help!

fulbay
8th December 2010, 13:54
Hello franz,

I could not understand the relation completely after my search. Could you please give more hints?

Thanks...

franz
8th December 2010, 19:54
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.

jkrienert
9th March 2015, 18:23
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.

jkrienert
10th March 2015, 12:34
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)-


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']
combo = QtGui.QComboBox(parent)
if index.row()>self.maxNumber: background = 'rgba(211,211,211,255)'
else: background = 'white'
combo.setStyleSheet('QComboBox{color:black;backgro und-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 ...