Results 1 to 3 of 3

Thread: How to resize the QIcon inside QPushButton dynamically?

  1. #1
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to resize the QIcon inside QPushButton dynamically?

    I have designed a keypad using QPushButton with Icons.

    For the keypad I have used QGridLayout, so the user can resize the keypad.

    Resizing works fine for the Buttons, but how can I resize the icon too?

    With seticon() I can change the icon and with setIconSize() I can change the size of the icon. But according to the manual - if I am right - I can set the size only as a fixed maximum size.

    Is there any other way to stretch the icon dynamically together with the Button?

    Thanks in advance.

  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: How to resize the QIcon inside QPushButton dynamically?

    I guess the way to go would be:
    1. Scale the icons image file to the maximal size it will need. (with a graphical editing application)
    2. call setIconSize() every time you change the size of the botton.
    ==========================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. The following user says thank you to high_flyer for this useful post:

    gboelter (18th February 2010)

  4. #3
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Unhappy Re: How to resize the QIcon inside QPushButton dynamically?

    Quote Originally Posted by high_flyer View Post
    I guess the way to go would be:
    1. Scale the icons image file to the maximal size it will need. (with a graphical editing application)
    2. call setIconSize() every time you change the size of the botton.
    Thanks! Because I don't have a better idea too, I will do it in this way now ....

    Qt Code:
    1. if ( event->type() == QEvent::Resize )
    2. {
    3. for ( int n = 0; n < pushButtonList.size(); ++n )
    4. {
    5. pushButtonList.at(n)->setIconSize( QSize( pushButtonList.at(n)->size().width()-4, pushButtonList.at(n)->size().height()-6 ));
    6. }
    7. ....
    To copy to clipboard, switch view to plain text mode 
    Thanks agai for giving me this idea ...

Similar Threads

  1. Replies: 4
    Last Post: 4th December 2009, 11:04
  2. QIcon resize question
    By MarkoSan in forum Qt Programming
    Replies: 0
    Last Post: 22nd November 2009, 22:35
  3. resize buttons inside
    By eleanor in forum Qt Programming
    Replies: 8
    Last Post: 21st October 2007, 06:21
  4. Dynamically resize spacing
    By trskel in forum Qt Programming
    Replies: 6
    Last Post: 28th September 2007, 12:52
  5. Replies: 2
    Last Post: 31st May 2006, 22:52

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.