How to remove the blue background from the table item when selected?

Asked

Viewed 31 times

0

I have a QTableWidget and I need all items in the table to have the same background color. The problem is that when an item is selected, it gets the background blue.

inserir a descrição da imagem aqui

I tried the following code on stylesheet, but it didn’t work:

QTableWidget {
    selection-background-color: transparent;
}

My question is: how can I remove this blue background when the item is selected using the stylesheet in Pyqt5?

1 answer

1

This is QSS (Qt Style Sheets, a style loosely similar to CSS), to style you can (should) refer to the official Qt documentation (and not your "Wrappers"), in the case of QSS styles:

In your specific case you want to style the selected items, then you have to use the pseudo-States to get the item in focus using :focus and to get the items (or other sub-controls) you must use the list QSS of sub-controls, in which case I believe to be the ::item

QTableWiget::item:focus {
    selection-background-color: transparent;
}

In addition you can experience the paintEvent, for many things ends up being even simpler than using QSS, but goes from case to case.

The only situations I couldn’t customize something with QSS was about elements within Qwebview (Qtwebkit), where I had to use QProxyStyle, but that’s because they were elements of which I had no control generated from the HTML rendering engine (Webkit).

  • He removed the background, but also "deleted" the texts. The text of the item is no longer visible. Also, my table has different color in each row, as in the question image. It would be possible to remove this blue background keeping the current color of the item?

  • @Jeanextreme002 tries the background-color: transparent;, as soon as there’s time I’ll test.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.