PDA

View Full Version : Using the "pixmap function" feature



Michiel
23rd May 2007, 21:21
I've seen that textfield. But I have no idea how it works. They don't explain it in the docs. All they say is:

"Finally, you can specify the function used to load pixmaps into the form window (the Pixmap Function)."

That's not a lot to go on. What signature should it have? Where do I define it? What should it do?

And more to the point: This is hardly a Designer feature if I still have to type a function for it myself. I was more expecting a small popup-dialog from the property editor where I could specify the properties and pixmaps for the QIcon.

I already have a function that creates the QIcons and attaches them to the QActions. Why would I need the "pixmap function" feature for that?

wysota
23rd May 2007, 22:55
I've seen that textfield. But I have no idea how it works.
See, I told you you didn't know everything about Designer :)


What signature should it have?
It should take a const char * or QString and return something which is acceptable by QIcon constructor.


Where do I define it?
Wherever you want.

What should it do?
Whatever you want it to as long as it returns something QIcon can take.


I was more expecting a small popup-dialog from the property editor where I could specify the properties and pixmaps for the QIcon.
Make one. Designer is GPLed. I prefer to have additions to Qt than to Designer :) And Trolltech has limited resources so they can't do everything. They did something that satisfies 90% of the cases and they gave us a way to fill the remaining 10%.


I already have a function that creates the QIcons and attaches them to the QActions. Why would I need the "pixmap function" feature for that?

To be able to do that from within Designer. I didn't say you needed it. I said there is a way to assign multiple pixmap icons to Designer created forms. I didn't say you can create the icons themselves in Designer.

Michiel
24th May 2007, 01:05
It should take a const char * or QString and return something which is acceptable by QIcon constructor.

Wherever you want.

I can't get it to work. I created the following function:


QIcon createIcon(QString iconName) {
QIcon result;

result.addFile(QString("images/%1_16x16.png").arg(iconName.toLower().replace(' ', '_')), QSize(16, 16));
result.addFile(QString("images/%1_22x22.png").arg(iconName.toLower().replace(' ', '_')), QSize(22, 22));
result.addFile(QString("images/%1_32x32.png").arg(iconName.toLower().replace(' ', '_')), QSize(32, 32));

return result;
}

I put it in my mainwindow.h, where the subclass of my main window sits.

And I put the word 'createIcon' inside the little textbox. And put mainwindow.h in the include hints.

But the function is never even called. I tried with some debug output.

Obviously I'm still missing something. Could you help me out?

Oh, and what's the string parameter supposed to represent anyway? I'm assuming here that it's the iconText property of the QAction.

I'm sure this could be a useful feature, but they should document it better. How could a person guess all this?

Michiel
24th May 2007, 02:10
Ok, I've guessed a little now. It's not the iconText, but the filename that it accepts.

The new function:


QIcon getIcon(QString iconName) {
QIcon result;

result.addFile(iconName.replace("32x32", "16x16"), QSize(16, 16));
result.addFile(iconName.replace("32x32", "22x22"), QSize(22, 22));
result.addFile(iconName , QSize(32, 32));

return result;
}

The files definitely exist, and the function is actually called now, but the icons are not loaded into the form. I even tried the absolute path, but that didn't work either. Strange.

Michiel
24th May 2007, 12:58
Ok, latest update. :) It sort of works now. It was just a stupid mistake of mine. But there is one additional question.

You can add different sizes to the same QIcon, right? But right now it seems to matter in which order I add them. If I use the function as written above, the toolbar will use 16x16 icons. If I put the 32x32 line on top, the toolbar uses 32x32 icons. What's with that?

Thanks!

(By the way, sorry for polluting the Designer thread. If a mod could maybe break my icon-question away to another thread?)

wysota
24th May 2007, 13:03
You can add different sizes to the same QIcon, right? But right now it seems to matter in which order I add them. If I use the function as written above, the toolbar will use 16x16 icons. If I put the 32x32 line on top, the toolbar uses 32x32 icons. What's with that?
I think you should use only one size of icons here but change the rest of the attributes (like the state). Qt will scale the icons if needed, so you might single sized pixmaps. At least I think so.



(By the way, sorry for polluting the Designer thread. If a mod could maybe break my icon-question away to another thread?)
Done.

Michiel
24th May 2007, 14:10
I think you should use only one size of icons here but change the rest of the attributes (like the state). Qt will scale the icons if needed, so you might single sized pixmaps. At least I think so.

That may be so, but it's not really the point. What if I didn't like how Qt scales the image? Or what if I want the small icons to really look different. Plus, Qt provides an interface to make it possible, so it should work. And it doesn't seem to.

The QIcon simply takes the first file I give it and disregards the rest.

wysota
24th May 2007, 15:05
Hard for me to argue with that. I only used different pixmaps for different states and let Qt handle the rest, so I don't know :)

Michiel
24th May 2007, 15:55
So will I. I happen to like the way Qt scales images. Also, to my pleasant surprise, Qt4 has made improvements in automatically creating disabled-state icons (now in real gray scale, instead of just a shadow), so I'll let Qt do that automatically too.

Well.. This simplifies things a bit. But it's still a bug.