Results 1 to 2 of 2

Thread: Pick size of QPixmap / icon based on DPI / user prefs

  1. #1
    Join Date
    Jan 2013
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Re: Pick size of QPixmap / icon based on DPI / user prefs

    I want to make a color picker available via a QPushButton. The button should have a color swatch (a QIcon) indication the object's current color. I need this to work adequately on both low and high dpi devices. How can I create an icon of the appropriate size?


    Added after 29 minutes:


    Here's one possible solution... correct me if there is a better way.

    QSomeWidget* widget ...
    QFont font = QApplication::font( widget );
    QFontMetrics metrics( font );

    int size = metrics.height() * 0.75f;
    QIcon( size, size );

    ...
    Last edited by stephelton; 12th January 2013 at 05:33.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Pick size of QPixmap / icon based on DPI / user prefs

    Hi,

    its not a better way but a shorter one:
    Qt Code:
    1. const int size = widget->fontMetrics().height() * 0.75f;
    To copy to clipboard, switch view to plain text mode 

    Best

Similar Threads

  1. Replies: 1
    Last Post: 13th January 2012, 07:09
  2. Replies: 0
    Last Post: 26th October 2010, 17:59
  3. Replies: 0
    Last Post: 19th February 2010, 16:33
  4. add(draw) an icon(or image) to a QPixmap?
    By ascii in forum Qt Programming
    Replies: 4
    Last Post: 20th November 2008, 12:44
  5. Replies: 5
    Last Post: 9th April 2007, 14:26

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.