chguy2
20th April 2007, 14:48
Hi guys,
I have a comboBox that displays colors with the last item that displays “otherâ€.
My code looks like:
comboBox_colors->addItem(“â€);
comboBox_colors->setItemData(0,Qt::red,Qt::BackgroundColorRole);
comboBox_colors->addItem(“â€);
comboBox_colors->setItemData(1,Qt::blue,Qt::BackgroundColorRole);
comboBox_colors->addItem(“â€);
comboBox_colors->setItemData(2,Qt::green,Qt::BackgroundColorRole);
…
comboBox_colors->addItem(“otherâ€);
comboBox_colors->setItemData(15,Qt::transparent,Qt::BackgroundColor Role);
I am having trouble disabling the highlight option because now when I scroll over the colors they change from whatever the color is to the highlight color. I tried changing the highlight color to white but it just changes the color from whatever to white.
I am also having trouble displaying the selected color in the comboBox when it is minimized. No matter what color is selected it will not display when the comboBox is minimized. So it always has a white background when the comboBox is minimized. The only time when I see something in the comboBox is when “other†is selected because “other†is displayed. Obviously if I put a word in the “†when I add the item, it will get displayed but I want it to display the color and no words.
If someone could help me out with this, it would be greatly appreciated. I have been suck on this for awhile.
*Maybe instead of disabling the highlight I can just set it to transparent? How do you change the color of the highlight in a comboBox in code? I only know how to change it using QT designer.*
I tried:
QPalette highlight;
QBrush trans(Qt::transparent);
trans.setStyle(Qt::SolidPattern);
highlight.setBrush(QPalette::Highlight,trans);
comboBox_colors->setPalette(highlight);
But that makes it white and not transparent.
Thanks.
I have a comboBox that displays colors with the last item that displays “otherâ€.
My code looks like:
comboBox_colors->addItem(“â€);
comboBox_colors->setItemData(0,Qt::red,Qt::BackgroundColorRole);
comboBox_colors->addItem(“â€);
comboBox_colors->setItemData(1,Qt::blue,Qt::BackgroundColorRole);
comboBox_colors->addItem(“â€);
comboBox_colors->setItemData(2,Qt::green,Qt::BackgroundColorRole);
…
comboBox_colors->addItem(“otherâ€);
comboBox_colors->setItemData(15,Qt::transparent,Qt::BackgroundColor Role);
I am having trouble disabling the highlight option because now when I scroll over the colors they change from whatever the color is to the highlight color. I tried changing the highlight color to white but it just changes the color from whatever to white.
I am also having trouble displaying the selected color in the comboBox when it is minimized. No matter what color is selected it will not display when the comboBox is minimized. So it always has a white background when the comboBox is minimized. The only time when I see something in the comboBox is when “other†is selected because “other†is displayed. Obviously if I put a word in the “†when I add the item, it will get displayed but I want it to display the color and no words.
If someone could help me out with this, it would be greatly appreciated. I have been suck on this for awhile.
*Maybe instead of disabling the highlight I can just set it to transparent? How do you change the color of the highlight in a comboBox in code? I only know how to change it using QT designer.*
I tried:
QPalette highlight;
QBrush trans(Qt::transparent);
trans.setStyle(Qt::SolidPattern);
highlight.setBrush(QPalette::Highlight,trans);
comboBox_colors->setPalette(highlight);
But that makes it white and not transparent.
Thanks.