I think you don't understand me (excuse me for my bad english), so i'm trying to explain better:
If i used color names like this:
colorNames <<"black"<<"white"<<"darkGray".... <-only some colors, not all
...
}
QStringList colorNames;
colorNames <<"black"<<"white"<<"darkGray".... <-only some colors, not all
...
foreach (QString name, colorName){
pixmap.fill(QColor(name));
CMBcolor[i]->addItem(QIcon(pixmap),"", QColor(name));
}
To copy to clipboard, switch view to plain text mode
the green color don't display (0,255,0), is a darkgreen, and darkyellow is black for me.
I don't know if this is a bug or not but the combo displays bad colors for these two (green and darkyellow, the other i use are well but probably there will be other colors that fails)
So why don't you omit those colors which you don't like ...
I programm the QStringList to avoid those colors i don't like (I only want 16 colors - white, black, red, darkRed, green, darkGreen, blue, darkBlue, cyan, darkCyan, magenta, darkMagenta, yellow, darkYellow, gray, darkGray, lightGray)
... or not use names at all?
I can avoid names of colors (I use them to complete the structure). But this is not the explanation why don't work my structure.
struct ColorData
{
int num;
int R;
int G;
int B;
}Propiedades[max_colors],*p;
...
ColorData Propiedades[max_colors] =
{
{ 0, "black", 0, 0, 0},
{ 1, "white",255,255,255},
{ 2, "darkGray",128,128,128},
{ 3, "gray",160,160,164},
...
};
p=&Propiedades[0];
struct ColorData
{
int num;
QString name;
int R;
int G;
int B;
}Propiedades[max_colors],*p;
...
ColorData Propiedades[max_colors] =
{
{ 0, "black", 0, 0, 0},
{ 1, "white",255,255,255},
{ 2, "darkGray",128,128,128},
{ 3, "gray",160,160,164},
...
};
p=&Propiedades[0];
To copy to clipboard, switch view to plain text mode
You can create a QColor by passing R, G and B components to QColor constructor.
Yes, i can. But i have to create the new colors each time i have to use them. So this is the reason to create a class with my colors.
If you really wish to have a separate structure holding the components (which is completely unnecessary as that's exactly what QColor does), why don't you do it like this?
Because if i pick the combo i need to know the r g b components of the color i have picked, and with this code i have to redefined my colors again (in other class). And I don't know how to obtain the rgb components of the color when i click in the combo (the selected item of the combo).
So if my class works I wouldn't be any problem. In the class i have clasified the colors for a single number what is the same that the position that the colors is in the combo. For example, if the combo return 1, i know that is the color white and i know elsewhere of the program the r,g,b components of this color.
connect(CMBcolor,SIGNAL(currentIndexChanged(int)),this,SLOT(CMBcolor_change(int)));
connect(CMBcolor,SIGNAL(currentIndexChanged(int)),this,SLOT(CMBcolor_change(int)));
To copy to clipboard, switch view to plain text mode
The current index is known in CMBcolor_change by the int variable. And with this integer i obtain the rgb components. With QColor i don't know how to do this because QColor use the name or the r,g,b but not the index.
As you can see i don't use the name of the color, as i say this is to complete the structure.
By all this i have decided to bulid the class.
Excuse me for my english and i hope you understand me.
Bookmarks