How to set color in QColorDialog ?
-
I have a QGraphicsScene which has many QGraphicsItem like rectangle, circle, lines etc.
I am coloring them by invoking color palette ( I have a button for color palette. Once that clicked, following code runs. )QColor color = QColorDialog::getColor(Qt::white, this, "Choose Color"); if (color.isValid()) { currentColor = color; }
And then I am using "currentColor" to color my QGraphicsItem from scene.
And at the same time, I am storing "currentColor" in std::map along with the QGraphicsItem which are colored with currentColor.What am I trying to solve ?
When next time I will open QColorDialog, it should scan map, and the color found in map, should be ticked in color dialog ( so that user will understand, which color are used in scene. )
So how to set color in QColorDialog ? -
What does, "the color found in map, should be ticked in color dialog," mean?
If you mean that these colours should be loaded in to the "Custom colors" part of the dialog then you use the QColorDialog::setCustomColor() and related functions.
Similarly, you can use the QColorDialog::setStandardColor() function.
-
What does, "the color found in map, should be ticked in color dialog," mean?
If you mean that these colours should be loaded in to the "Custom colors" part of the dialog then you use the QColorDialog::setCustomColor() and related functions.
Similarly, you can use the QColorDialog::setStandardColor() function.
@ChrisW67 Thank you for your reply.
I am trying to say like this :Lets say , I selected "Red" color and color I1 and I2 QGraphicsItem with it.
Then I selected "Green" color and color I3 and I4 QGraphicsItem with it.
Then I selected "Yellow" color and color I5 QGraphicsItem with it.
Then my map entry will be :
Red - I1, I2
Green - I3, I4
Yellow - I5So next time when I will open QColorDialog, It should scan map , and read color "Red", "Green" and "Yellow" and mark them in it's palette. So User will know, I have chosen 3 colors.
Now if user wants to de-highlight one of the color group then he will unticked through QColorDialog. And all the QGraphicsItem colored with that color will be de-highlighted. ( that's a feature I am trying to implement)So I want, how to mark color in QColorDialog ?