PDA

View Full Version : Color combobox



chguy2
4th April 2007, 16:29
Hi,

I am having some trouble trying to find and/or make a combo box (or something similar) that shows different colors rather than text or numbers. Right now I have a text box and if you type in the HTML color and click ok the font color will change. But I would much rather some kind of combo that displays a couple default colors instead.

Thanks for the help.

high_flyer
4th April 2007, 17:25
Why don't you just use QColorDialog?

marcel
4th April 2007, 17:36
Create your own custom QAbstractItemDelegate and QAbstractItem if you want to do complex drawing on the combo items.

Otherwise just use QComboBox::insertItem and pass an empty string as the first parameter and for the second a QVariant( pix ), where pix should be your pixmap filled with the color you want. Passing an empty string should provide the result you mentioned.

Marcel

jpn
4th April 2007, 17:43
How about something like this? :)


comboBox->addItem("red");
comboBox->setItemData(0, Qt::red, Qt::BackgroundRole);
comboBox->addItem("green");
comboBox->setItemData(1, Qt::green, Qt::BackgroundRole);
comboBox->addItem("blue");
comboBox->setItemData(2, Qt::blue, Qt::BackgroundRole);

patrik08
4th April 2007, 17:47
or on the fly icon ... and all name color from QT...






void Interface::populateFilter(QComboBox *comboBox)
{
QPixmap pix(22, 22);

QStringList colorNames = QColor::colorNames();
comboBox->addItem(tr("Select a filter.."));
pix.fill(QColor("grey"));
comboBox->addItem(pix,tr("GreyScale"));
comboBox->addItem(tr("RGB Swapped"));
comboBox->addItem(tr("InvertPixels color"));
pix.fill(QColor(162,128,101));
comboBox->addItem(pix,tr("Colorize")+QString(" color=\"sepia\""));
comboBox->addItem(tr("Colorize")+QString(" color=\"mycolor\""));

foreach (QString name, colorNames) {

pix.fill(QColor(name));
comboBox->addItem(pix,tr("Colorize")+QString(" color=\"%1\"").arg(name));
}
}

chguy2
4th April 2007, 18:00
wow, thanks a lot.
I'll post back if I hve any more problems

chguy2
5th April 2007, 13:44
I am having one small problem now:
In the comboBox, when you scroll over the color it changes color because it mixes blue (the highlighter) of the mouse with the color and changes the appearance of the color.
Is there an easy way to disable that highlighter? or changing it somehow?

Thanks for the help!

patrik08
5th April 2007, 13:51
I am having one small problem now:
In the comboBox, when you scroll over the color it changes color because it mixes blue (the highlighter) of the mouse with the color and changes the appearance of the color.
Is there an easy way to disable that highlighter? or changing it somehow?

Thanks for the help!

chance palette to white or make a border on color....

code from http://qt-webdav.svn.sourceforge.net/viewvc/qt-webdav/html_editor/
html editor && image editor from subdir http://sourceforge.net/projects/qt-webdav/

http://www.qtcentre.org/forum/attachment.php?attachmentid=1041&stc=1&d=1175777429


of topic... is chguy2 indended from switzerland?

wysota
5th April 2007, 14:21
I have a widget that is a combobox that allows to pick colours from a user defined set of options. It'll be published as part of a larger widget set after Easter. So keep your eyes open if you're interested.

chguy2
5th April 2007, 14:23
I changed the palette to white, but now when I scroll down the colors go from red, blue, green to white when they are highlighted. I also can't find that: Filter apply. I guess its too good to be true. I am using Qt 4.2.2.

What I am trying to do is just make this one comboBox highlight disabled or set to transparent.

And sorry Patrik, I am from Canada.