Results 1 to 7 of 7

Thread: selection color of the items delegated in a tree widget

  1. #1
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default 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...
    Last edited by fulbay; 3rd December 2010 at 13:41.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: selection color of the items delegated in a tree widget

    Did you use the style aware QStyledItemDelegate to implement your delegates?
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default 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!

  4. #4
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default 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...

  5. #5
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  6. The following user says thank you to franz for this useful post:

    fulbay (9th December 2010)

  7. #6
    Join Date
    Dec 2014
    Posts
    48
    Thanks
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    Windows

    Default 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.
    Last edited by jkrienert; 9th March 2015 at 19:01.

  8. #7
    Join Date
    Dec 2014
    Posts
    48
    Thanks
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    Windows

    Default 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)-

    Qt Code:
    1. class comboDelegate(QtGui.QStyledItemDelegate):
    2. def __init__(self, parent, maxNumber):
    3. QtGui.QStyledItemDelegate.__init__(self, parent)
    4. self.maxNumber = int(maxNumber)
    5. def createEditor(self, parent, option, index):
    6. self.comboChoices = ['pen','keyboard','sword']
    7. combo = QtGui.QComboBox(parent)
    8. if index.row()>self.maxNumber: background = 'rgba(211,211,211,255)'
    9. else: background = 'white'
    10. combo.setStyleSheet('QComboBox{color:black;background-color:'+background+';\
    11. border-color:black;border-width: 0px;border-style:solid;}\
    12. QComboBox QAbstractItemView{outline:0px;}\
    13. QComboBox::drop-down{subcontrol-origin:padding;\
    14. subcontrol-position:center right;width:10px;right:2px;\
    15. border-top-right-radius:0px;border-bottom-right-radius:0px;\
    16. background:none;}')
    17. combo.addItems(self.comboChoices)
    18. combo.currentIndexChanged[int].connect(self.currentIndexChanged)
    19. return combo
    20.  
    21. #... Some other Delegate related functions ...
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QComboBox with multipe selection via tree
    By corwinj in forum Qt-based Software
    Replies: 2
    Last Post: 20th February 2015, 16:41
  2. Replies: 2
    Last Post: 20th August 2010, 05:18
  3. Context Menu for specific items in a Tree Widget
    By manekineko in forum Qt Programming
    Replies: 0
    Last Post: 16th November 2009, 01:46
  4. Tree selection - icon transparency (lack of)
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2008, 21:48
  5. Replies: 14
    Last Post: 9th November 2006, 08:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.