lundi 20 avril 2015

Change color of particular QTableView rows with StyleSheets [duplicate]

This question already has an answer here:

I am working on an music application that has a QTableView with a list of tracks. When I select one and hit play, I would like to change its row's color. I know I can do it in the data() function of the model, however the new color to be applied has to be taken out of a style.qss file where the style for the whole application is stored. I read a bit about dynamic properties but I couldn't see how to apply them to specific rows. Is there a class for a QTablewView's item? If there is I could do something like:

MagicItemClass[played="true"] {
background-color: #something
color: #something

and then use setProperty() and unpolish() and polish() functions.

Another desperate attempt would be to parse the style.qss and get the color and return it in the data() function.

However I really think there must be a better solution.

So do you know of any "MagicItemClass"? Or do you have any other ideas on how to implement this feature?

EDIT: I saw: How to set stylesheet for the current item in QTableView
However this is not the solution I was looking for. This sets only the current row's color. I would like that color to remain even after another one is selected to be played. The new color's whole point is to distinguish played tracks from unplayed more easily.

UPDATE: Ok. Let me reformulate. I saw the question that was answered. Its solution doesn't work for me. I don't want to change the color of the item in focus. I want it to be permanent. Plus if the user clicks on a row in a table that doesn't mean it's been played(however it is in focus). I saw the pseudo states and couldn't find one that fits(I may need a custom one, is there anything like this?).

Aucun commentaire:

Enregistrer un commentaire