How can I change the color and font of "QListWidgetItem" dynamically?
-
This post is deleted!
-
This post is deleted!
@Zbigniew-Sch said in How can I change the color and font of "QListWidgetItem" dynamically?:
but later I can't change the parameters.
Why not?
-
This post is deleted!
-
This post is deleted!
@Zbigniew-Sch
It should change. Show where you call the update from, how we know which itempcoListItem->points to and the values for font/color which are clearly different from what they presently are. -
Everything is correct, but I can't change the color and font:
QListWidgetItem* pcoListItem = this->item(0);
pcoListItem->setFont(font());
pcoListItem->setForeground(Qt::black);I created item with blue color (display is correct)
If I set "pcoListItem->setData(Qt::ItemDataRole::UserRole + 1, "XXXX");"
then everything works correctly but the file path for this item is not correct -
It is possible values from the
data()/setData()methods in the model override your explicit attempts to set values, I do not know.setData(Qt::ItemDataRole::UserRole + 1, "XXXX");Qt widgets does not use
UserRole + 1for anything by default. It looks like you are using this, somehow/somewhere. What do you mean "then everything works correctly", how does changing the value forUserRole + 1affect the font and the color? What is"XXXX"?I created item with blue color (display is correct)
And did you do that via a call to
setForeground()or viadata()/setData()code? How should we know?but the file path for this item is not correct
What "file path"?
QListWidgetItemdoes not use "file paths" for anything.Maybe you need to await someone else who can understand what you are saying.
-
This post is deleted!
-
This post is deleted!
-
This post is deleted!
@Zbigniew-Sch
Assuming you don't get an answer from someone on the information you have provided, I think you need to post a minimal example of complete, runnable code which goes wrong for people to look at.