Results 1 to 14 of 14

Thread: My mode to displaying QIcons

  1. #1
    Join Date
    Feb 2012
    Posts
    10
    Qt products
    Qt4

    Question My mode to displaying QIcons

    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:
    scr1.jpg

    Thanks.
    Last edited by Borland; 15th March 2012 at 13:01.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: My mode to displaying QIcons

    Can i create my mode with my render or change any mode?
    If you know how to subclass, sure.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2012
    Posts
    10
    Qt products
    Qt4

    Default Re: My mode to displaying QIcons

    Sorry, i don't understand how i can change color.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: My mode to displaying QIcons

    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
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Feb 2012
    Posts
    10
    Qt products
    Qt4

    Default Re: My mode to displaying QIcons

    i'm sorry that my question not specific.

    Standart modes for QIcon:

    Disabled:
    MaximumDisabled.png

    Active:
    MaximumActive.jpg

    I need to create my specific mode
    MyDisable:
    MaximumAverage.png

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

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: My mode to displaying QIcons

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Feb 2012
    Posts
    10
    Qt products
    Qt4

    Default Re: My mode to displaying QIcons

    Quote Originally Posted by high_flyer View Post
    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:
    Qt Code:
    1. QPainter painter(&pixmap);
    2. painter.drawPixmap(QPoint(0, 0), pixmap);
    3. painter.fillRect(0, 0, 128, 128, QColor(100, 100, 100, 180));
    To copy to clipboard, switch view to plain text mode 
    and result:
    painterAverage.png
    but i need
    MaximumAverage.jpg

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

  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: My mode to displaying QIcons

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Feb 2012
    Posts
    10
    Qt products
    Qt4

    Default Re: My mode to displaying QIcons

    Drawing my custom icon in a standard situation? Do you mean:
    Qt Code:
    1. for (int i = 0; i < NumModes; ++i){
    2. QIcon::Mode mode;
    3. if (i == 0) {
    4. mode = QIcon::Active;
    5. } else if (i == 1) {
    6. mode = QIcon::Selected;
    7. } else if (i == 2) {
    8. mode = QIcon::Disabled;
    9. }
    10. else if(i == 3){
    11. mode = QIcon::Active;
    12. }
    13. pixmap = icon.pixmap(size, mode, QIcon::Off);
    14. QPixmap onIcon("on.png");
    15. QPixmap offIcon("off.png");
    16. icon.addPixmap(onIcon, QIcon::Active);
    17. icon.addPixmap(offIcon, QIcon::Disabled);
    18.  
    19. pixmapLabels[i]->setPixmap(pixmap);
    20. pixmapLabels[i]->setEnabled(true);
    21. }
    To copy to clipboard, switch view to plain text mode 
    For example, i have 30 differents "ON" icons which looks like MaximumActive.png
    In this way i must create 30 differents "OFF" icons which looks like MaximumAverage.jpg? 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 MaximumAverage.jpg but not gray like this:
    screen.jpg

    Thank you.

  10. #10
    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: My mode to displaying QIcons

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Feb 2012
    Posts
    10
    Qt products
    Qt4

    Default Re: My mode to displaying QIcons

    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?

  12. #12
    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: My mode to displaying QIcons

    Quote Originally Posted by Borland View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Feb 2012
    Posts
    10
    Qt products
    Qt4

    Default Re: My mode to displaying QIcons

    Quote Originally Posted by wysota View Post
    There is no QGuessWhatIWantAndDoIt class in Qt.
    Sometimes I regret that there is no such class

    This code decrease saturation for each pixel:
    Qt Code:
    1. QImage img;
    2. img = pixmap.toImage();
    3. int w = img.width();
    4. int h = img.height();
    5. for (int y = 0; y < h; ++y)
    6. {
    7. for(int x = 0; x < w; ++x)
    8. {
    9. QColor pixel = img.pixel(x, y);
    10. pixel.setHsl(pixel.hue(), 30, pixel.lightness(), pixel.alpha());
    11. img.setPixel(x, y, pixel.rgba());
    12. }
    13. }
    14. //return QPixmap::fromImage(img, Qt::AutoColor)
    To copy to clipboard, switch view to plain text mode 
    What do you think, It is not too time-consuming process?

  14. #14
    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: My mode to displaying QIcons

    If it works for you then it's ok.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Qt 4.4 - Problem displaying pixmap in release mode
    By spawn9997 in forum Qt Programming
    Replies: 0
    Last Post: 19th August 2009, 19:40
  2. Replies: 1
    Last Post: 23rd April 2009, 09:05
  3. SVG QICONs not appearing after deploy (QT 4.2.2)
    By donmorr in forum Installation and Deployment
    Replies: 2
    Last Post: 29th March 2007, 13:16
  4. QVariant - storing QIcons[]
    By moowy in forum Qt Programming
    Replies: 7
    Last Post: 25th August 2006, 00:41
  5. QIcons
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2006, 13:11

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.