Results 1 to 9 of 9

Thread: Using the "pixmap function" feature

  1. #1
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Do you use the designer, or do you code your gui manually?

    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?
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Do you use the designer, or do you code your gui manually?

    Quote Originally Posted by Michiel View Post
    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.

  3. #3
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Do you use the designer, or do you code your gui manually?

    Quote Originally Posted by wysota View Post
    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:

    Qt Code:
    1. QIcon createIcon(QString iconName) {
    2. QIcon result;
    3.  
    4. result.addFile(QString("images/%1_16x16.png").arg(iconName.toLower().replace(' ', '_')), QSize(16, 16));
    5. result.addFile(QString("images/%1_22x22.png").arg(iconName.toLower().replace(' ', '_')), QSize(22, 22));
    6. result.addFile(QString("images/%1_32x32.png").arg(iconName.toLower().replace(' ', '_')), QSize(32, 32));
    7.  
    8. return result;
    9. }
    To copy to clipboard, switch view to plain text mode 

    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?
    Last edited by Michiel; 24th May 2007 at 01:09. Reason: reformatted to look better
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  4. #4
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Do you use the designer, or do you code your gui manually?

    Ok, I've guessed a little now. It's not the iconText, but the filename that it accepts.

    The new function:

    Qt Code:
    1. QIcon getIcon(QString iconName) {
    2. QIcon result;
    3.  
    4. result.addFile(iconName.replace("32x32", "16x16"), QSize(16, 16));
    5. result.addFile(iconName.replace("32x32", "22x22"), QSize(22, 22));
    6. result.addFile(iconName , QSize(32, 32));
    7.  
    8. return result;
    9. }
    To copy to clipboard, switch view to plain text mode 

    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.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  5. #5
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Do you use the designer, or do you code your gui manually?

    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?)
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Do you use the designer, or do you code your gui manually?

    Quote Originally Posted by Michiel View Post
    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.

  7. #7
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Do you use the designer, or do you code your gui manually?

    Quote Originally Posted by wysota View Post
    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.
    Last edited by Michiel; 24th May 2007 at 14:17.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Do you use the designer, or do you code your gui manually?

    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

  9. #9
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Do you use the designer, or do you code your gui manually?

    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.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.