PDA

View Full Version : My mode to displaying QIcons



Borland
15th March 2012, 13:46
Hi!
QIcon have Mode { Normal, Disabled, Active, Selected }
I need average color between Disabled (grayed out) and Selected (blued out).
Can i create my mode with my render or change any mode?

Screenshot:
7506

Thanks.

high_flyer
16th March 2012, 09:21
Can i create my mode with my render or change any mode?
If you know how to subclass, sure.

Borland
16th March 2012, 10:40
Sorry, i don't understand how i can change color.

high_flyer
16th March 2012, 11:19
I am not clear on what you question is about?
Is it about how to change a color in an image, or how to extend QIcon to have more modes?
Please ask clear and specific question, and not force us to play 20 questions with you to figure out what you want.
http://www.catb.org/~esr/faqs/smart-questions.html

Borland
16th March 2012, 16:01
i'm sorry that my question not specific.

Standart modes for QIcon:

Disabled:
7508

Active:
7509

I need to create my specific mode
MyDisable:
7510

I hope you can help me understand how to do it.

high_flyer
16th March 2012, 16:12
You still didn't answer my question.
At any rate here are both answers:
If you want to change how QIcon is changing an image for a disabled mode, you will have to subclass QIcon.
If your question is about how to manipulate an image - have a look at QImage.

If none of the above answers your question, please invest more in explaining what you need.

Borland
18th March 2012, 09:09
If you want to change how QIcon is changing an image for a disabled mode, you will have to subclass QIcon.


Yes, i want it. But i can't understand how i can solve it using subclass of QIcon.
I try:


QPainter painter(&pixmap);
painter.drawPixmap(QPoint(0, 0), pixmap);
painter.fillRect(0, 0, 128, 128, QColor(100, 100, 100, 180));
and result:
7517
but i need
7518

Sorry, you can show me simple example how using subclass of QIcon solve it?

wysota
18th March 2012, 13:40
Do you intend to call this extended functionality yourself or do you expect to somehow teach Qt to draw your custom icon in a standard situation? In other words, how do you want to use your custom "MyDisable" mode?

Borland
18th March 2012, 16:36
Drawing my custom icon in a standard situation? Do you mean:


for (int i = 0; i < NumModes; ++i){
QIcon::Mode mode;
if (i == 0) {
mode = QIcon::Active;
} else if (i == 1) {
mode = QIcon::Selected;
} else if (i == 2) {
mode = QIcon::Disabled;
}
else if(i == 3){
mode = QIcon::Active;
}
pixmap = icon.pixmap(size, mode, QIcon::Off);
QPixmap onIcon("on.png");
QPixmap offIcon("off.png");
icon.addPixmap(onIcon, QIcon::Active);
icon.addPixmap(offIcon, QIcon::Disabled);

pixmapLabels[i]->setPixmap(pixmap);
pixmapLabels[i]->setEnabled(true);
}

For example, i have 30 differents "ON" icons which looks like 7520
In this way i must create 30 differents "OFF" icons which looks like 7519? It's not good.

I intend to increase saturation of current icon (Active mode) and other icons (in MyDisable mode) must be with low saturation like 7519 but not gray like this:
7521

Thank you.

wysota
18th March 2012, 16:47
So what you want is not a new mode but different look of icons in some of the modes that are already there, right?

If you were to implement a new mode (ok, let's say this clear -- you can't add modes to QIcon), you would have to provide some piece of code that transforms one pixmap (e.g. icon in active mode) into another (e.g. icon in disabled mode). So if you have such code then simply run it for your 30 icons and use QIcon::addPixmap() to set them to be used for one of available modes.

Borland
18th March 2012, 17:19
I do not have code that transforms one pixmap (e.g. icon in active mode) into another (e.g. icon in disabled mode). How to transform icons? Using QImage? But how decrease saturation of image using QImage?

wysota
18th March 2012, 17:29
I do not have code that transforms one pixmap (e.g. icon in active mode) into another (e.g. icon in disabled mode).
So how did you want to add this new mode? There is no QGuessWhatIWantAndDoIt class in Qt.


But how decrease saturation of image using QImage?

Decrease the saturiation value of the color for each pixel.

Borland
18th March 2012, 18:18
There is no QGuessWhatIWantAndDoIt class in Qt.


Sometimes I regret that there is no such class :)

This code decrease saturation for each pixel:


QImage img;
img = pixmap.toImage();
int w = img.width();
int h = img.height();
for (int y = 0; y < h; ++y)
{
for(int x = 0; x < w; ++x)
{
QColor pixel = img.pixel(x, y);
pixel.setHsl(pixel.hue(), 30, pixel.lightness(), pixel.alpha());
img.setPixel(x, y, pixel.rgba());
}
}
//return QPixmap::fromImage(img, Qt::AutoColor)

What do you think, It is not too time-consuming process?

wysota
18th March 2012, 19:11
If it works for you then it's ok.