pyqt5 qtablewidget cell background while editing cell

FurkanOzcelik :
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

musicamante :

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.

edited at
0

Comments

0 comments
Login to comment

Related

JavaFX Table Cell Editing

Why is cancelCellEditing() not called when pressing escape while editing a JTable cell?

PyQt5: get index of cell widgets and their chosen values

How to show image and text at same cell in QTableWidget in PyQt?

Sending a signal to highlight cell in QtableWidget PyQt

How to make background of cell widget inside QTableWidget not selectable?

Highlight Cell in a QTableWidget PyQt5

How to popup QCompleter on entering cell editing in QTableWidget

PyQt5 QTableWidget cell select, save and copy

PyQt5 Highlighting a selected TreeWidget cell

remove space in QTableWidget cell

How to change background color of selected or clicked cell in a pyqt5 QTableWidget?

copy paste text in label in QTableWidget cell PyQt5

How to connect a QRadioButton of a QTableWidget cell with another QTableWidget cell using an arrow?

Editing a Number cell in a TableView

Tableviews, cell editing and dragging

PyQt5 QTableView cell editing behaviour - superimposition of original value

In PyQt5, How to add a QSpinBox inside a QTreeWidget cell?

Go To Position of Visual Cell on QTableWidget

QTableWidget or QTableView for toggling cell images

catch double click on calendar date cell PyQt5

Vertically centering a QLineEdit in QWidget in QTableWidget cell in PyQt5?

Remove cell padding from QTableWidget in PyQt5

PyQt5 How to press enter on a QTableWidget and go to the cell below?

Pyqt5 qtablewidget detect when a cell changes

How to select a cell in QTableWidget programmatically

How to put a TextEdit inside a cell in QTableWidget - Pyqt5?

Background color of the particular cell is not changing after clicking specific cells in qTableWidget pyqt5

Pyqt5: Hyperlink in table's cell