self.grid.setStyleSheet("QTableWidget::item::selected { background-color:#F9F6F5 ; color:black;
border: 3px solid black; }")
currently i'm using styleSheet for my qtablewidget background when i select an item it changes that cell's background like this which is what i want
but when i start editing it is back to default settings like this and i dont know which keyword should i use instead of 'item::selected' or if it even exists
You can use the descendant css selector, which can be used to specify the style for a widget that is descendant of another (it could be a direct child, a "grandchild", etc).
Editing of item views is usually done with a QLineEdit, the solution is to use QTableWidget QLineEdit
, and since the styling is going to be the same, you can also concatenate the selectors with commas:
self.grid.setStyleSheet('''
QTableWidget::item::selected, QTableWidget QLineEdit {
background-color: #F9F6F5;
color: black;
border: 3px solid black;
}
''')
Note that you need the descendant selector, not the child selector (parent > child
) which is for direct children only: the editor of an item view is not a direct child of the view, as an item view has the following hierarchy:
item view -> viewport (the scrollable contents) -> editor
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments